mc_mixed: Mixed Models Structure

View source: R/mc_mixed.R

mc_mixedR Documentation

Mixed Models Structure

Description

Constructs the components of the matrix linear predictor associated with mixed-effects covariance structures in multivariate covariance generalized linear models. The function builds symmetric matrices representing variance and covariance components as functions of known covariates, following a linear mixed model formulation.

The mc_mixed function is primarily intended for repeated measures and longitudinal data, where observations are collected within a fixed number of groups, subjects, or experimental units.

Usage

mc_mixed(formula, data)

Arguments

formula

A model formula specifying the structure of the matrix linear predictor for the dispersion component. The first term must remove the intercept (0 +), and the second term must identify the grouping variable (e.g., subject or unit), which must be a factor. Additional covariates may be specified after a slash (/) to define random slopes and associated covariance components.

data

A data.frame containing all variables referenced in formula.

Details

The formula argument follows a syntax similar to that used for linear mixed models. The grouping variable must be provided as the second term in the formula and must be a factor; no internal coercion is performed. Covariates specified after the slash (/) may be continuous or categorical and define additional variance and covariance components. When only the grouping variable is specified (e.g., ~ 0 + SUBJECT), the resulting structure corresponds to the compound symmetry covariance model.

By default, all pairwise interaction terms between components are included in the matrix linear predictor. Interaction terms may be excluded by removing the corresponding components from the resulting list.

Value

A list of symmetric sparse matrices of class "dsCMatrix", each corresponding to a variance or covariance component of the matrix linear predictor for the dispersion structure. The list includes matrices associated with main effects and, by default, their pairwise interaction terms as implied by the mixed-effects specification in the formula. These matrices are used internally to construct the linear predictor of the covariance model in mcglm. It is intended to be supplied to the matrix_pred argument of mcglm.

Author(s)

Wagner Hugo Bonat, wbonat@ufpr.br

Source

Bonat, W. H. (2018). Multiple Response Variables Regression Models in R: The mcglm Package. Journal of Statistical Software, 84(4), 1–30.

Bonat, W. H., et al. (2016). Modelling the covariance structure in marginal multivariate count models: Hunting in Bioko Island. Journal of Agricultural, Biological, and Environmental Statistics, 22(4), 446–464.

See Also

mc_id, mc_conditional_test, mc_dist, mc_ma, mc_rw, mc_car

Examples

SUBJECT <- gl(2, 6)
x1 <- rep(1:6, 2)
x2 <- rep(gl(2, 3), 2)
data <- data.frame(SUBJECT, x1, x2)

# Compound symmetry structure
mc_mixed(~ 0 + SUBJECT, data = data)

# Compound symmetry with random slope for x1
mc_mixed(~ 0 + SUBJECT/x1, data = data)

# Compound symmetry with random slopes for x1 and x2 and interactions
mc_mixed(~ 0 + SUBJECT/(x1 + x2), data = data)


mcglm documentation built on Jan. 9, 2026, 1:07 a.m.