Learn R Programming

lava (version 1.11)

predict.estimate.mmrm: Predictions at a single visit from mmrm models

Description

Predictions at a single visit from an mmrm model

Usage

# S3 method for estimate.mmrm
predict(object, newdata = NULL, time = NULL, p = coef(object), ...)

Value

Named numeric vector (subject IDs) with attributes observed

(logical) and time.

Arguments

object

(estimate.mmrm) estimate of an mmrm model obtained with estimate(fit, sigma = TRUE).

newdata

(data.frame) long-format data with the subject and visit variables, covariates and (optionally) the response. Defaults to the data used to fit the model.

time

(integer) index of the visit to predict (default last visit).

p

(numeric) parameter vector on the scale of coef(object): mean parameters followed by the upper-triangular elements (column-major, including the diagonal) of the covariance matrix of each group.

...

additional arguments (not used)

Details

For each subject in newdata, returns the outcome at visit time if it is observed, and otherwise the conditional mean given the observed outcomes of the subject. With \(O\) the observed visits of subject \(i\), $$E(Y_{it} \mid Y_{iO}) = x_{it}^\top\beta + \Sigma_{tO}\Sigma_{OO}^{-1}(Y_{iO} - X_{iO}\beta),$$ where \(\Sigma\) is the (group-specific) covariance matrix of all visits (the marginal mean \(x_{it}^\top\beta\) if no outcomes are observed). This corresponds to predict(fit, newdata, conditional = TRUE) of the mmrm package.

newdata is first expanded to all subject and visit combinations with complete_visits().

Examples

Run this code
if (requireNamespace("mmrm", quietly = TRUE)) {
  data(fev_data, package = "mmrm")
  fit <- mmrm::mmrm(
    FEV1 ~ ARMCD * AVISIT + us(AVISIT | USUBJID),
    data = fev_data, reml = FALSE,
    optimizer = "nlminb"
  )
  e <- estimate(fit, sigma = TRUE)
  predict(e, newdata = subset(fev_data, USUBJID %in% c("PT1", "PT2")))
}

Run the code above in your browser using DataLab