effects.lmm: Effects Derived For a Linear Mixed Model

View source: R/effects.R

effects.lmmR Documentation

Effects Derived For a Linear Mixed Model

Description

Estimate average counterfactual outcome or contrast of outcome based on a linear mixed model.

Usage

## S3 method for class 'lmm'
effects(
  object,
  variable,
  effects = "identity",
  type = "outcome",
  repetition = NULL,
  conditional = NULL,
  ref.repetition = 1,
  ref.variable = 1,
  newdata = NULL,
  rhs = NULL,
  multivariate = FALSE,
  prefix.time = NULL,
  prefix.var = TRUE,
  sep.var = ",",
  ...
)

Arguments

object

a lmm object.

variable

[character/list] exposure variable relative to which the effect should be computed. Can also be a list with two elements: the first being the variable (i.e. a character) and the second the levels or values for this variable to be considered.

effects

[character] should the average counterfactual outcome for each variable level be evaluated ("identity")? Or the difference in average counterfactual outcome between each pair of variable level ("difference")?

type

[character/numeric vector] Possible transformation of the outcome: no transformation ("outcome"), change from baseline ("change"), area under the outcome curve ("auc"), or area under the outcome curve minus baseline ("auc-b"). Alternatively can be a numeric vector indicating how to weight each timepoint.

repetition

[character vector] repetition at which the effect should be assessed. By default it will be assessed at all repetitions.

conditional

[character/data.frame] variable(s) conditional to which the average conterfactual outcome or treatment effect should be computed. Alternatively can also be a data.frame where each column correspond to a variable and the rows to the level of the variable(s).

ref.repetition

[numeric or character] index or value of the reference level for the repetition variable. Only relevant when type equal to "change". Can be NA to evaluate change relative to all possible reference levels.

ref.variable

[numeric or character] index or value of the reference level for the exposure variable. Only relevant when effects equal to "difference". Can be NA to evaluate the difference relative to all possible reference levels.

newdata

[data.frame] a dataset reflecting the covariate distribution relative to which the average outcome or contrast should be computed.

rhs

[numeric] the right hand side of the hypothesis.

multivariate

[logical] should a multivariate Wald test be used to simultaneously test all null hypotheses.

prefix.time

[character] When naming the estimates, text to be pasted before the value of the repetition variable. Only relevant when type = "aoc" or type = "ate".

prefix.var

[logical] When naming the estimates, should the variable name be added or only the value?

sep.var

[character] When naming the estimates, text to be pasted between the values to condition on. Only relevant when type = "aoc" or type = "ate".

...

Arguments passed to anova.lmm.

Details

The uncertainty is quantified assuming the contrast matrix to be a-priori known. Said otherwise the standard error does not account for the uncertainty about the covariate distribution.

Examples

#### simulate data in the long format ####
set.seed(10)
dL <- sampleRem(100, n.times = 3, format = "long")

#### Linear Mixed Model ####
eUN.lmm <- lmm(Y ~ visit + X1 + X2 + X5,
               repetition = ~visit|id, structure = "UN", data = dL)

## outcome
e.YbyX1 <- effects(eUN.lmm, variable = "X1")
e.YbyX1
summary(e.YbyX1)
model.tables(e.YbyX1)
coef(e.YbyX1, type = "contrast")
effects(eUN.lmm, effects = "difference", variable = "X1")
effects(eUN.lmm, effects = "difference", variable = "X1", repetition = "3")

## change
effects(eUN.lmm, type = "change", variable = "X1")
effects(eUN.lmm, type = "change", variable = "X1", ref.repetition = 2)
effects(eUN.lmm, type = "change", variable = "X1", conditional = NULL)
effects(eUN.lmm, type = "change", effects = "difference", variable = "X1")

## auc
effects(eUN.lmm, type = "auc", variable = "X1")
effects(eUN.lmm, type = "auc", effects = "difference", variable = "X1")

#### fit Linear Mixed Model with interaction ####
dL$X1.factor <- as.factor(dL$X1)
dL$X2.factor <- as.factor(dL$X2)
eUN.lmmI <- lmm(Y ~ visit * X1.factor + X2.factor + X5,
               repetition = ~visit|id, structure = "UN", data = dL)

## average counterfactual conditional to a categorical covariate
effects(eUN.lmmI, variable = "X1.factor",
        conditional = "X2.factor", repetition = "3")
effects(eUN.lmmI, type = "change", variable = "X1.factor",
        conditional = "X2.factor", repetition = "3")
effects(eUN.lmmI, type = "auc", variable = "X1.factor", conditional = "X2.factor")

## average difference in counterfactual conditional to a categorical covariate
effects(eUN.lmmI, effects = "difference", variable = "X1.factor",
        conditional = c("X2.factor"), repetition = "3")
effects(eUN.lmmI, effects = "difference", type = "change", variable = "X1.factor",
        conditional = c("X2.factor"), repetition = "3")
effects(eUN.lmmI, effects = "difference", type = "auc", variable = "X1.factor",
        conditional = "X2.factor")

## average difference in counterfactual conditional to a covariate
effects(eUN.lmmI, effect = "difference", variable = "X1.factor",
        conditional = data.frame(X5=0:2), repetition = "3")
effects(eUN.lmmI, effect = "difference", type = "change", variable = "X1.factor",
        conditional = data.frame(X5=0:2))

bozenne/handrem documentation built on Oct. 21, 2024, 8:40 a.m.