Skip to contents

Generates a linear model object to estimate a treatment effect, with proper estimation of variances accounting for the study specification.

Usage

lmitt(obj, specification, data, ...)

# S3 method for class 'formula'
lmitt(
  obj,
  specification,
  data,
  absorb = FALSE,
  offset = NULL,
  weights = NULL,
  ...
)

# S3 method for class 'lm'
lmitt(obj, specification = NULL, ...)

Arguments

obj

A formula or a lm object. See Details.

specification

The StudySpecification to be used. Alternatively, a formula creating a specification (of the type of that would be passed as the first argument to rd_spec(), rct_spec(), or obs_spec()). If the formula includes a forcing() element, an RD specification is created. Otherwise an observational specification is created. An RCT specification must be created manually using rct_spec().

data

A data.frame such as would be passed into lm().

...

Additional arguments passed to lm(). One such argument is dichotomy, which can be used to dichotomize a non-binary treatment variable in specification. See the Details section of the ett() or att() help pages for information on specifying this formula.

absorb

If TRUE, fixed effects are included for blocks identified in the StudySpecification. Excluded in FALSE. Default is FALSE. 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 of cov_adj().

weights

Which weights should be generated? Options are "ate" or "ett". Alternatively, the output of a manually run ate() or ett() can be used.

Value

teeMod model.

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 StudySpecification creation functions (e.g. rct_spec()) take an optional subset= argument used in the creation of the StudySpecification, this is not the same as the subset= argument passed to lm() or lmitt(). The subset= argument when creating a StudySpecification restricts the data used to generate the StudySpecification, but has no direct impact on the future lm() or lmitt() calls using that StudySpecification. (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 specification 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 StudySpecification 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)
spec <- rct_spec(z ~ unit_of_assignment(uoa1, uoa2), data = simdata)
mod1 <- lmitt(y ~ 1, data = simdata, specification = spec, weights = "ate")
mod2 <- lmitt(y ~ as.factor(o), data = simdata, specification = spec, weights = "ate")
mod3 <- lmitt(y ~ 1, data = simdata,
              specification = z ~ uoa(uoa1, uoa2) + forcing(force))