Fits a linear model that uses weights and variance estimates appropriate for the data.
lm.sdf(formula, data, weightVar = NULL, relevels = list(),
varMethod = c("jackknife", "Taylor"), jrrIMax = 1,
dropOmittedLevels = TRUE, defaultConditions = TRUE, recode = NULL,
returnVarEstInputs = FALSE, returnNumberOfPSU = FALSE,
standardizeWithSamplingVar = FALSE, verbose=TRUE,
omittedLevels = deprecated())
An edsurvey.lm
with the following elements:
the function call
the formula used to fit the model
the estimates of the coefficients
the standard error estimates of the coefficients
the estimated variance from uncertainty in the scores (plausible value variables)
the estimated variance from sampling
the number of plausible values
the variance estimates under the various plausible values
the values of the coefficients under the various plausible values
the coefficient matrix (typically produced by the summary of a model)
the coefficient of determination
the name of the weight variable
the number of plausible values
the jrrIMax
value used in computation
the number of the jackknife replicates used; set to NA
when Taylor series variance estimates are used
one of Taylor series
or the jackknife
residuals from the average regression coefficients
residuals from the by plausible value coefficients
fitted values from the by plausible value coefficients
imputation variance covariance matrix, before multiplication by (M+1)/M
sampling variance covariance matrix
average relative increase in variance; see van Buuren (2012, eq. 2.29)
number of PSUs used in calculation
number of rows on an edsurvey.data.frame
before any conditions were applied
number of observations with valid data and weights larger than zero
data used for the computation
standard deviations of regressors, used for computing standardized
regression coefficients when standardizeWithSamplingVar
is set to
FALSE
(the default)
the result of running summary2
(unweighted) on each variable in the
regression
when returnVarEstInputs
is TRUE
,
this element is returned. These are
used for calculating covariances with
varEstToCov
.
when standardizeWithSamplingVar
is set to TRUE
, this element is
returned. Calculates the standard deviation
of the standardized
regression coefficients like any other
variable.
a formula
for the
linear model. See lm
.
If y is left blank, the default subject scale or subscale variable
will be used. (You can find the default using
showPlausibleValues
.)
If y is a variable for a subject scale or subscale (one of the
names shown by showPlausibleValues
),
then that subject scale or subscale is used.
an edsurvey.data.frame
, a light.edsurvey.data.frame
,
or an edsurvey.data.frame.list
a character indicating the weight variable to use (see Details).
The weightVar
must be one of the weights for the
edsurvey.data.frame
. If NULL
, it uses the default
for the edsurvey.data.frame
.
a list. Used to change the contrasts from the default treatment contrasts to the treatment contrasts with a chosen omitted group (the reference group). The name of each element should be the variable name, and the value should be the group to be omitted (the reference group).
a character set to “jackknife” or “Taylor” that indicates the variance estimation method to be used. See Details.
a numeric value; when using the jackknife variance estimation method, the default estimation option, jrrIMax=1
, uses the
sampling variance from the first plausible value as the component for sampling variance estimation. The Vjrr
term (see
Statistical Methods Used in EdSurvey)
can be estimated with any number of plausible values, and values larger than the number of
plausible values on the survey (including Inf
) will result in all plausible values being used.
Higher values of jrrIMax
lead to longer computing times and more accurate variance estimates.
a logical value. When set to the default value of TRUE
, drops
those levels of all factor variables that are specified
in an edsurvey.data.frame
. Use print
on an
edsurvey.data.frame
to see the omitted levels.
a logical value. When set to the default value of TRUE
, uses
the default conditions stored in an edsurvey.data.frame
to subset the data. Use print
on an
edsurvey.data.frame
to see the default conditions.
a list of lists to recode variables. Defaults to NULL
. Can be set as
recode=
list(
var1
=
list(
from=
c("a",
"b",
"c"),
to=
"d"))
. See Examples.
a logical value set to TRUE
to return the
inputs to the jackknife and imputation variance
estimates, which allow for the computation
of covariances between estimates.
a logical value set to TRUE
to return the number of
primary sampling units (PSUs)
a logical value indicating if the standardized coefficients
should have the variance of the regressors and outcome measured
with sampling variance. Defaults to FALSE
.
logical; indicates whether a detailed printout should display during execution
this argument is deprecated. Use dropOmittedLevels
Of the common hypothesis tests for joint parameter testing, only the Wald
test is widely used with plausible values and sample weights. As such, it
replaces, if imperfectly, the Akaike Information Criteria (AIC), the
likelihood ratio test, chi-squared, and analysis of variance (ANOVA, including F-tests). See waldTest
or
the vignette titled
Methods and Overview of Using EdSurvey for Running Wald Tests.
Paul Bailey
This function implements an estimator that correctly handles left-hand side variables that are either numeric or plausible values and allows for survey sampling weights and estimates variances using the jackknife replication method. The vignette titled Statistical Methods Used in EdSurvey describes estimation of the reported statistics.
Regardless of the variance estimation, the coefficients are estimated using the sample weights according to the sections “Estimation of Weighted Means When Plausible Values Are Not Present” or “Estimation of Weighted Means When Plausible Values Are Present,” depending on if there are assessment variables or variables with plausible values in them.
How the standard errors of the coefficients are estimated depends on the
value of varMethod
and the presence of plausible values (assessment variables),
But once it is obtained, the t statistic
is given by $$t=\frac{\hat{\beta}}{\sqrt{\mathrm{var}(\hat{\beta})}}$$ where
\( \hat{\beta} \) is the estimated coefficient and \(\mathrm{var}(\hat{\beta})\) is
the variance of that estimate.
The coefficient of determination (R-squared value) is similarly estimated by finding the average R-squared using the average across the plausible values.
Standardized regression coefficients can be returned in a call to summary
,
by setting the argument src
to TRUE
. See Examples.
By default, the standardized coefficients are calculated using standard
deviations of the variables themselves, including averaging the standard
deviation across any plausible values. When standardizeWithSamplingVar
is set to TRUE
, the variance of the standardized coefficient is
calculated similar to a regression coefficient and therefore includes the
sampling variance in the variance estimate of the outcome variable.
All variance estimation methods are shown in the vignette titled
Statistical Methods Used in EdSurvey.
When varMethod
is set to the jackknife
and the predicted
value does not have plausible values, the variance of the coefficients
is estimated according to the section
“Estimation of Standard Errors of Weighted Means When
Plausible Values Are Not Present, Using the Jackknife Method.”
When plausible values are present and varMethod
is jackknife
, the
variance of the coefficients is estimated according to the section
“Estimation of Standard Errors of Weighted Means When
Plausible Values Are Present, Using the Jackknife Method.”
When plausible values are not present and varMethod
is Taylor
, the
variance of the coefficients is estimated according to the section
“Estimation of Standard Errors of Weighted Means When Plausible
Values Are Not Present, Using the Taylor Series Method.”
When plausible values are present and varMethod
is Taylor
, the
variance of the coefficients is estimated according to the section
“Estimation of Standard Errors of Weighted Means When Plausible
Values Are Present, Using the Taylor Series Method.”
Binder, D. A. (1983). On the variances of asymptotically normal estimators from complex surveys. International Statistical Review, 51(3), 279--292.
Rubin, D. B. (1987). Multiple imputation for nonresponse in surveys. New York, NY: Wiley.
van Buuren, S. (2012). Flexible imputation of missing data. New York, NY: CRC Press.
Weisberg, S. (1985). Applied linear regression (2nd ed.). New York, NY: Wiley.
if (FALSE) {
# read in the example data (generated, not real student data)
sdf <- readNAEP(path=system.file("extdata/data", "M36NT2PM.dat", package = "NAEPprimer"))
# by default uses jackknife variance method using replicate weights
lm1 <- lm.sdf(formula=composite ~ dsex + b017451, data=sdf)
lm1
# the summary function displays detailed results
summary(lm1)
# to show standardized regression coefficients
summary(lm1, src=TRUE)
# to specify a variance method, use varMethod
lm2 <- lm.sdf(formula=composite ~ dsex + b017451, data=sdf, varMethod="Taylor")
lm2
summary(lm2)
# use relevel to set a new omitted category
lm3 <- lm.sdf(formula=composite ~ dsex + b017451, data=sdf, relevels=list(dsex="Female"))
summary(lm3)
# test of a simple joint hypothesis
waldTest(lm3, "b017451")
# use recode to change values for specified variables
lm4 <- lm.sdf(formula=composite ~ dsex + b017451, data=sdf,
recode=list(b017451=list(from=c("Never or hardly ever",
"Once every few weeks",
"About once a week"),
to=c("Infrequently")),
b017451=list(from=c("2 or 3 times a week","Every day"),
to=c("Frequently"))))
# Note: "Infrequently" is the dropped level for the recoded b017451
summary(lm4)
}
Run the code above in your browser using DataLab