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("STARplus")
##' A prognostic model fitted to experimental + non-experimental controls
y0hat_read <- lm(read_yr1 ~ gender*dob + race,
data = STARplus,
subset = cond_at_entry!="small")
STARspec <- rct_spec(cond_at_entry ~ unit_of_assignment(stdntid) +
block(grade_at_entry, school_at_entry),
subset=!is.na(grade_at_entry),# excludes non-experimentals
data = STARplus)
ett_wts <- ett(STARspec, data = STARplus,
dichotomy= cond_at_entry =="small" ~.)
ett_read <- lm(read_yr1 ~ assigned(dichotomy= cond_at_entry =="small" ~.),
### expect warning about NAs generated here:
offset = cov_adj(y0hat_read),
data = STARplus,
weights = ett_wts)
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
coef(ett_read)
#> (Intercept)
#> 11.716479
#> assigned(dichotomy = cond_at_entry == "small" ~ .)
#> 2.740331
ett_read |> as.lmitt() |> vcov()
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
#> (Intercept)
#> (Intercept) 5.129557
#> assigned(dichotomy = cond_at_entry == "small" ~ .) 1.141797
#> read_yr1:(Intercept) -1.167347
#> cov_adj:(Intercept) -6.296904
#> assigned(dichotomy = cond_at_entry == "small" ~ .)
#> (Intercept) 1.141797
#> assigned(dichotomy = cond_at_entry == "small" ~ .) 6.180492
#> read_yr1:(Intercept) -1.901156
#> cov_adj:(Intercept) -3.042953
#> read_yr1:(Intercept)
#> (Intercept) -1.167347
#> assigned(dichotomy = cond_at_entry == "small" ~ .) -1.901156
#> read_yr1:(Intercept) 2.046614
#> cov_adj:(Intercept) 3.213961
#> cov_adj:(Intercept)
#> (Intercept) -6.296904
#> assigned(dichotomy = cond_at_entry == "small" ~ .) -3.042953
#> read_yr1:(Intercept) 3.213961
#> cov_adj:(Intercept) 9.510865
#> attr(,"type")
#> [1] "CR0"
ate_read <- lmitt(read_yr1 ~ 1, STARspec, STARplus,
dichotomy= cond_at_entry =="small" ~.,
offset = cov_adj(y0hat_read),
weights = "ate")
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
show(ate_read)
#> cond_at_entry. read_yr1:(Intercept)
#> 5.815509 548.669478
coef(ate_read)
#> (Intercept) cond_at_entry. read_yr1:(Intercept)
#> 2.539062 5.815509 548.669478
#> cov_adj:(Intercept)
#> 546.130416
vcov(ate_read)
#> (Intercept) cond_at_entry. read_yr1:(Intercept)
#> (Intercept) 4.111796 1.928425 -1.888967
#> cond_at_entry. 1.928425 10.313178 -1.163048
#> read_yr1:(Intercept) -1.888967 -1.163048 1.208415
#> cov_adj:(Intercept) -6.000763 -3.091473 3.097382
#> cov_adj:(Intercept)
#> (Intercept) -6.000763
#> cond_at_entry. -3.091473
#> read_yr1:(Intercept) 3.097382
#> cov_adj:(Intercept) 9.098144
#> attr(,"type")
#> [1] "CR0"
ate_read_loc <-
lmitt(read_yr1 ~ race, STARspec, STARplus,
dichotomy= cond_at_entry =="small" ~.,
offset = cov_adj(y0hat_read, newdata = STARplus),
weights = "ate")
#> Warning: Some covariance adjustments are NA; be careful of dropping these observations when fitting the ITT effect model
show(ate_read_loc)
#> cond_at_entry._racewhite cond_at_entry._raceblack cond_at_entry._raceasian
#> 2.498286 10.192583 9.587866
#> cond_at_entry._racehispa cond_at_entry._racenatam cond_at_entry._raceother
#> 24.973857 -13.308205 -58.945590
#> cond_at_entry._racemssng read_yr1:racewhite read_yr1:raceblack
#> 23.726705 559.648184 534.368939
#> read_yr1:raceasian read_yr1:racehispa read_yr1:racenatam
#> 546.942099 523.741414 511.580037
#> read_yr1:raceother read_yr1:racemssng
#> 566.392747 561.330830