Generates a linear model object to estimate a treatment effect, with proper estimation of variances accounting for the study design.
Usage
lmitt(obj, design, data, ...)
# S3 method for class 'formula'
lmitt(obj, design, data, absorb = FALSE, offset = NULL, weights = NULL, ...)
# S3 method for class 'lm'
lmitt(obj, design = NULL, ...)
Arguments
- obj
A
formula
or alm
object. See Details.- design
The
Design
to be used. Alternatively, a formula creating a design (of the type of that would be passed as the first argument tord_design()
,rct_design()
, orobs_design()
). If the formula includes aforcing()
element, an RD design is created. Otherwise an observational design is created. An RCT design must be created manually usingrct_design()
.- data
A
data.frame
such as would be passed intolm()
.- ...
Additional arguments passed to
lm()
. One such argument isdichotomy
, which can be used to dichotomize a non-binary treatment variable indesign
. See the Details section of theett()
oratt()
help pages for information on specifying this formula.- absorb
If
TRUE
, fixed effects are included for blocks identified in theDesign
. Excluded inFALSE
. Default isFALSE
. The estimates of these fixed effects are suppressed from the returned object.- offset
Offset of the kind which would be passed into
lm()
. Ideally, this should be the output ofcov_adj()
.- weights
Which weights should be generated? Options are
"ate"
or"ett"
. Alternatively, the output of a manually runate()
orett()
can be used.
Details
The first argument to lmitt()
should be a formula specifying the
outcome on the left hand side. The right hand side of the formula can be
any of the following:
1
: Estimates a main treatment effect.a subgroup variable: Estimates a treatment effect within each level of your subgrouping variable.
a continuous moderator: Estimates a main treatment effect as well as a treatment by moderator interaction. The moderator is not automatically centered.
Alternatively, obj
can be a pre-created lm
object. No
modification is made to the formula of the object. See the help for
as.lmitt()
for details of this conversion.
Note that although the Design
creation functions (e.g.
rct_design()
) take an optional subset=
argument used in the
creation of the Design
, this is not the same as the
subset=
argument passed to lm()
or lmitt()
. The subset=
argument when creating a Design
restricts the data used to generate
the Design
, but has no direct impact on the future lm()
or
lmitt()
calls using that Design
. (It can indirectly have an
impact by excluding particular units of assignment from receiving a
treatment assignment and thus complete case analysis removes them from the
model.)
On the other hand, the subset=
argument in lm()
or lmitt()
refers
only to subsetting the data
argument passed into lm()
or lmitt()
.
To avoid variable name collision, the treatment variable defined in the
design
will have a ".
" appended to it. For example, if you
request a main treatment effect (with a formula of ~ 1
) with a
treatment variable named "txt", you can obtain it's estimate from the
returned teeMod
object via $coefficients["txt."]
.
lmitt()
will produce a message if the Design
passed in has block
information that is not being utilized in the model. Note that this is
not an error, but could be an oversight. To disable this message, run
options("propertee_message_on_unused_blocks" = FALSE)
.
Examples
data(simdata)
des <- rct_design(z ~ unit_of_assignment(uoa1, uoa2), data = simdata)
mod1 <- lmitt(y ~ 1, data = simdata, design = des, weights = "ate")
mod2 <- lmitt(y ~ as.factor(o), data = simdata, design = des, weights = "ate")
mod3 <- lmitt(y ~ 1, data = simdata,
design = z ~ uoa(uoa1, uoa2) + forcing(force))