When passing a lm
object to lmitt()
, extract and use
the treatment variable specified in the StudySpecification
.
Usage
assigned(specification = NULL, data = NULL, dichotomy = NULL)
adopters(specification = NULL, data = NULL, dichotomy = NULL)
a.(specification = NULL, data = NULL, dichotomy = NULL)
z.(specification = NULL, data = NULL, dichotomy = NULL)
Arguments
- specification
Optional
StudySpecification
. If theStudySpecification
can't be identified in the model (usually because neither weights (ate()
orett()
) nor a covariate adjustment model (cov_adj()
) are found), theStudySpecification
can be passed diretly.- data
Optional data set. By default
assigned()
will attempt to identify the appropriate data, if this fails (or you want to overwrite it), you can pass the data here.- dichotomy
optional; a formula defining the dichotomy of the treatment variable if it isn't already
0
/1
. See details for more information. Ifett()
orate()
is called within almitt()
call that specifies adichotomy
argument, thatdichotomy
will be used if the argument here has not been specified.
Details
When passing a lm
object to lmitt()
, the treatment
variable in the formula
passed to lm()
needs to be identifiable.
Rather than placing the treatment variable directly in the formula
,
use one of these functions, to allow lmitt()
to identify the treatment
variable.
To keep the formula in the lm()
call concise, instead of passing
specification
and data
arguments to these functions, one can
pass a WeightedStudySpecification
object to the weights
argument of the lm()
call or a SandwichLayer
object to the
offset
argument.
Alternatively, you can pass the specification
and data
arguments.
While assigned()
can be used in any situation, it is most useful
for scenarios where the treatment variable is non-binary and the
StudySpecification
contains a Dichotomy
. For example, say
q
is a 3-level ordinal treatment variable, and the binary
comparison of interest is captured in dichotomy = q == 3 ~ q < 3
.
If you were to fit a model including q
as a predictor, e.g.
lm(y ~ q, ...)
, lm
would treat q
as the full ordinal
variable. On the other hand, by calling lm(y ~ assigned(), weights =
ate(spec), ...)
, assigned()
will generate the appropriate binary
variable to allow estimation of treatment effects.
If called outside of a model call and without a data
argument, this
will extract the treatment from the specification
. If this is the
goal, the treatment()
function is better suited for this purpose.
Examples
data(simdata)
spec <- obs_spec(z ~ uoa(uoa1, uoa2), data = simdata)
mod <- lm(y ~ assigned(), data = simdata, weights = ate(spec))
lmittmod <- lmitt(mod)
summary(lmittmod)
#>
#> Call:
#> lmitt(mod)
#>
#> Coefficients :
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -0.0090 0.1734 -0.052 0.959
#> assigned() 0.1205 0.2301 0.524 0.603
#> Std. Error calculated via type "CR0"
#>