cov_adj()
takes a fitted covariance model and returns
the information necessary for adjusting direct adjustment model estimates
and associated standard errors for covariates. Standard errors will
reflect adjustments made to the outcomes as well as contributions to
sampling variability arising from the estimates of the covariance
adjustment model coefficients.
Arguments
- model
any model that inherits from a
glm
,lm
, orrobustbase::lmrob
object- newdata
a dataframe of new data. Default is NULL, in which case a dataframe is sought from higher up the call stack.
- specification
a
StudySpecification
object. Default is NULL, in which case aStudySpecification
object is sought from higher up the call stack.- by
optional; a string or named vector of unique identifier columns in the data used to create
specification
and the data used to fit the covariance adjustment model. Default is NULL, in which case unit of assignment columns are used for identification (even if they do not uniquely identify units of observation). If a named vector is provided, names should represent variables in the data used to createspecification
, while values should represent variables in the covariance adjustment data.
Value
A SandwichLayer
if specification
is not NULL or a
StudySpecification
object is found in the call stack, otherwise a
PreSandwichLayer
object
Details
Prior to generating adjustments, cov_adj()
identifies the
treatment variable specified in the StudySpecification
object
passed to specification
and replaces all values with a reference
level. If the treatment has logical type, this reference level is
FALSE
, and if it has numeric type, this is the smallest
non-negative value (which means 0 for 0/1 binary). Factor treatments are
not currently supported for StudySpecification
objects.
The
values of the output vector represent adjustments for the outcomes in
newdata
if newdata
is provided; adjustments for the outcomes
in the data used to fit a teeMod
model if cov_adj()
is
called within the offset
argument of the model fit; or they are the
fitted values from model
if no relevant dataframe can be extracted
from the call stack. The length of the output of cov_adj()
will
match the number of rows of the dataframe used.
Examples
data(STARdata)
STARdata$treatment <- STARdata$stark == "small"
STARdata$treatment[is.na(STARdata$treatment)] <- FALSE
STARdata$studentid <- as.character(seq_len(nrow(STARdata)))
covariance_y0_read <- lm(readk ~ gender + ethnicity + lunchk +
ladderk + experiencek + tethnicityk,
data = STARdata, subset = !treatment)
STARdata_spec <- rct_spec(treatment ~ cluster(studentid), data = STARdata)
STARdata_ate <- ate(STARdata_spec, data = STARdata)
STARdata_ett <- ett(STARdata_spec, data = STARdata)
ett_read <- lm(readk ~ treatment,
offset = cov_adj(covariance_y0_read, newdata = STARdata),
data = STARdata,
weights = STARdata_ett)
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
coef(ett_read)
#> (Intercept) treatmentTRUE
#> -1.079602e-13 5.554179e+00
ate_read <- lm(readk ~ treatment,
offset = cov_adj(covariance_y0_read, newdata = STARdata),
data = STARdata,
weights = STARdata_ate)
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
coef(ate_read)
#> (Intercept) treatmentTRUE
#> -1.022791e-13 5.554179e+00
ate_read_eth <- lm(readk ~ treatment * ethnicity,
offset = cov_adj(covariance_y0_read, newdata = STARdata),
data = STARdata,
weights = STARdata_ate)
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
coef(ate_read_eth)
#> (Intercept) treatmentTRUE
#> -9.603676e-14 5.901494e+00
#> ethnicityafam ethnicityasian
#> -1.612015e-14 1.965411e-14
#> ethnicityhispanic ethnicityamindian
#> 6.700549e-13 1.565857e-15
#> ethnicityother treatmentTRUE:ethnicityafam
#> -6.431281e-14 -1.289929e+00
#> treatmentTRUE:ethnicityasian treatmentTRUE:ethnicityhispanic
#> -2.494972e+01 3.214437e+01
#> treatmentTRUE:ethnicityamindian treatmentTRUE:ethnicityother
#> 1.391799e+01 3.202748e+00