Fits a Mixed Model Repeated Measures model (see Details). In this implementation, the fixed effects structure is flexible -- it is user defined using a formula. This implementation does not support the inclusion of random effects.
Usage
mmrm(
formula,
time,
subjects,
data,
categorical_time = TRUE,
heterogenous = TRUE,
cov_struct = c("unstructured", "toeplitz", "autoregressive", "compound-symmetry",
"identity"),
method = "REML",
na.action = na.exclude,
control = list(),
verbose = FALSE,
return_all = FALSE,
stop_on_convergence = TRUE,
...
)
Arguments
- formula
formula for the fixed effects structure of the model
- time
the time variable of the model
- subjects
the variable indicating unique subjects
- data
the data structure
- categorical_time
logical indicating whether time should be a categorical (factor) or continuous (numeric) variable
- heterogenous
boolean flag for heterogenous vs. homogenous variance. If heterogenous = TRUE, uses different variance parameters at each time point. If heterogenous = FALSE, one variance paramter across all time points.
- cov_struct
a sequence of covariance matrix specifications; will fit a model starting with the first covariance and check for convergence. If there are convergence issues, it will iterate through the rest of the list until the model converges.
- method
character, either "REML" or "ML". If "REML" the model is fit by maximizing the restricted log-likelihood. If "ML" the log-likelihood is maximized. Defaults to "REML".
- na.action
a function that indicates what should happen when the data contain NAs. Defaults to na.omit
- control
a list of control values fo the estimation algorithm to to replace the default values returned by the function nlme::glsControl
- verbose
logical value indicating whether to print the evolution of the iterative algorithm. Default is FALSE
- return_all
logical; if TRUE, will return all models that were fit, if FALSE, only returns the first model that converged or last model attempted (if all failed).
- stop_on_convergence
ignored if return_all = FALSE. if return_all = TRUE, stop fitting models and return results once one model converges if stop_on_convergence = TRUE. if return_all = TRUE and stop_on_convergence = FALSE, fits and returns all specified models
Value
mmrmObject
or mmrmList
, a list of mmrmObjects
If return_all = FALSE, returns only the mmrmObject of the first model to
converge or the last attempted model.
If return_all = TRUE, returns list of all attempted models.
Details
The MMRM implemented here is defined as: $$Y_i = X_i\beta + \epsilon_i$$ $$\epsilon_i \sim \mathcal{N}(0, \Sigma_i)$$
\(Y_i\) as the vector of outcomes with length \(n_{subjects}*n_{timepoints}\)
\(X_i\) as the a matrix of predictors with \(n_{subjects}*n_{timepoints}\) rows and \(n_{predictors}\) columns
\(\beta\) as the vector of coefficients with length \(n_{predictors}\)
\(\epsilon_i\) as the vector of residuals
\(\Sigma_i\) as the (\(n_{subjects}*n_{timepoints} x n_{subjects}*(n_{timepoints}\)) covariance matrix
This implementation of the MMRM supports four different covariance structures: unstructured, toeplitz, AR(1), and compound symmetry.