The function mc_mixed helps to build the components of the matrix linear predictor associated with mixed models. It is useful to model the covariance structure as a function of known covariates in a linear mixed model fashion (Bonat, et. al. 2016). The mc_mixed function was designed to analyse repeated measures and longitudinal data, where in general the observations are taken at a fixed number of groups, subjects or unit samples.

mc_mixed(formula, data)

Arguments

formula

a formula model to build the matrix linear predictor. See details.

data

data set.

Source

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

Bonat, 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.

Value

A list of matrices.

Details

The formula argument should be specified similar to the linear predictor for the mean structure, however the first component should be 0 and the second component should always indicate the name of the column containing the subject or unit sample index. It should be a factor. The other covariates are specified after a slash "\" in the usual way. For example, ~0 + SUBJECT/(x1 + x2) means that the column SUBJECT contains the subject or unit sample index, while the covariates that can be continuous or factors are given in the columns x1 and x2. Be careful the parenthesis after the "\" are mandatory, when including more than one covariate. The special case where only the SUBJECT effect is requested the formula takes the form ~ 0 + SUBJECT without any extra covariate. This structure corresponds to the well known compound symmetry structure. By default the function mc_mixed include all interaction terms, the users can ignore the interactions terms removing them from the matrix linear predictor.

See also

mc_id, mc_conditional_test, mc_dist, mc_ma, mc_rw and 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)
#> [[1]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 1 1 1 1 1 1 . . . . . . #> 2 1 1 1 1 1 1 . . . . . . #> 3 1 1 1 1 1 1 . . . . . . #> 4 1 1 1 1 1 1 . . . . . . #> 5 1 1 1 1 1 1 . . . . . . #> 6 1 1 1 1 1 1 . . . . . . #> 7 . . . . . . 1 1 1 1 1 1 #> 8 . . . . . . 1 1 1 1 1 1 #> 9 . . . . . . 1 1 1 1 1 1 #> 10 . . . . . . 1 1 1 1 1 1 #> 11 . . . . . . 1 1 1 1 1 1 #> 12 . . . . . . 1 1 1 1 1 1 #>
# Compound symmetry + random slope for x1 and interaction or correlation mc_mixed(~0 + SUBJECT/x1, data = data)
#> [[1]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 1 1 1 1 1 1 . . . . . . #> 2 1 1 1 1 1 1 . . . . . . #> 3 1 1 1 1 1 1 . . . . . . #> 4 1 1 1 1 1 1 . . . . . . #> 5 1 1 1 1 1 1 . . . . . . #> 6 1 1 1 1 1 1 . . . . . . #> 7 . . . . . . 1 1 1 1 1 1 #> 8 . . . . . . 1 1 1 1 1 1 #> 9 . . . . . . 1 1 1 1 1 1 #> 10 . . . . . . 1 1 1 1 1 1 #> 11 . . . . . . 1 1 1 1 1 1 #> 12 . . . . . . 1 1 1 1 1 1 #> #> [[2]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 1 2 3 4 5 6 . . . . . . #> 2 2 4 6 8 10 12 . . . . . . #> 3 3 6 9 12 15 18 . . . . . . #> 4 4 8 12 16 20 24 . . . . . . #> 5 5 10 15 20 25 30 . . . . . . #> 6 6 12 18 24 30 36 . . . . . . #> 7 . . . . . . 1 2 3 4 5 6 #> 8 . . . . . . 2 4 6 8 10 12 #> 9 . . . . . . 3 6 9 12 15 18 #> 10 . . . . . . 4 8 12 16 20 24 #> 11 . . . . . . 5 10 15 20 25 30 #> 12 . . . . . . 6 12 18 24 30 36 #> #> [[3]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 2 3 4 5 6 7 . . . . . . #> 2 3 4 5 6 7 8 . . . . . . #> 3 4 5 6 7 8 9 . . . . . . #> 4 5 6 7 8 9 10 . . . . . . #> 5 6 7 8 9 10 11 . . . . . . #> 6 7 8 9 10 11 12 . . . . . . #> 7 . . . . . . 2 3 4 5 6 7 #> 8 . . . . . . 3 4 5 6 7 8 #> 9 . . . . . . 4 5 6 7 8 9 #> 10 . . . . . . 5 6 7 8 9 10 #> 11 . . . . . . 6 7 8 9 10 11 #> 12 . . . . . . 7 8 9 10 11 12 #>
# Compound symmetry + random slope for x1 and x2 plus interactions mc_mixed(~0 + SUBJECT/(x1 + x2), data = data)
#> [[1]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 1 1 1 1 1 1 . . . . . . #> 2 1 1 1 1 1 1 . . . . . . #> 3 1 1 1 1 1 1 . . . . . . #> 4 1 1 1 1 1 1 . . . . . . #> 5 1 1 1 1 1 1 . . . . . . #> 6 1 1 1 1 1 1 . . . . . . #> 7 . . . . . . 1 1 1 1 1 1 #> 8 . . . . . . 1 1 1 1 1 1 #> 9 . . . . . . 1 1 1 1 1 1 #> 10 . . . . . . 1 1 1 1 1 1 #> 11 . . . . . . 1 1 1 1 1 1 #> 12 . . . . . . 1 1 1 1 1 1 #> #> [[2]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 1 2 3 4 5 6 . . . . . . #> 2 2 4 6 8 10 12 . . . . . . #> 3 3 6 9 12 15 18 . . . . . . #> 4 4 8 12 16 20 24 . . . . . . #> 5 5 10 15 20 25 30 . . . . . . #> 6 6 12 18 24 30 36 . . . . . . #> 7 . . . . . . 1 2 3 4 5 6 #> 8 . . . . . . 2 4 6 8 10 12 #> 9 . . . . . . 3 6 9 12 15 18 #> 10 . . . . . . 4 8 12 16 20 24 #> 11 . . . . . . 5 10 15 20 25 30 #> 12 . . . . . . 6 12 18 24 30 36 #> #> [[3]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 . . . . . . . . . . . . #> 2 . . . . . . . . . . . . #> 3 . . . . . . . . . . . . #> 4 . . . 1 1 1 . . . . . . #> 5 . . . 1 1 1 . . . . . . #> 6 . . . 1 1 1 . . . . . . #> 7 . . . . . . . . . . . . #> 8 . . . . . . . . . . . . #> 9 . . . . . . . . . . . . #> 10 . . . . . . . . . 1 1 1 #> 11 . . . . . . . . . 1 1 1 #> 12 . . . . . . . . . 1 1 1 #> #> [[4]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 2 3 4 5 6 7 . . . . . . #> 2 3 4 5 6 7 8 . . . . . . #> 3 4 5 6 7 8 9 . . . . . . #> 4 5 6 7 8 9 10 . . . . . . #> 5 6 7 8 9 10 11 . . . . . . #> 6 7 8 9 10 11 12 . . . . . . #> 7 . . . . . . 2 3 4 5 6 7 #> 8 . . . . . . 3 4 5 6 7 8 #> 9 . . . . . . 4 5 6 7 8 9 #> 10 . . . . . . 5 6 7 8 9 10 #> 11 . . . . . . 6 7 8 9 10 11 #> 12 . . . . . . 7 8 9 10 11 12 #> #> [[5]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 . . . 1 1 1 . . . . . . #> 2 . . . 1 1 1 . . . . . . #> 3 . . . 1 1 1 . . . . . . #> 4 1 1 1 2 2 2 . . . . . . #> 5 1 1 1 2 2 2 . . . . . . #> 6 1 1 1 2 2 2 . . . . . . #> 7 . . . . . . . . . 1 1 1 #> 8 . . . . . . . . . 1 1 1 #> 9 . . . . . . . . . 1 1 1 #> 10 . . . . . . 1 1 1 2 2 2 #> 11 . . . . . . 1 1 1 2 2 2 #> 12 . . . . . . 1 1 1 2 2 2 #> #> [[6]] #> 12 x 12 sparse Matrix of class "dsCMatrix"
#> [[ suppressing 12 column names ‘1’, ‘2’, ‘3’ ... ]]
#> #> 1 . . . 1 1 1 . . . . . . #> 2 . . . 2 2 2 . . . . . . #> 3 . . . 3 3 3 . . . . . . #> 4 1 2 3 8 9 10 . . . . . . #> 5 1 2 3 9 10 11 . . . . . . #> 6 1 2 3 10 11 12 . . . . . . #> 7 . . . . . . . . . 1 1 1 #> 8 . . . . . . . . . 2 2 2 #> 9 . . . . . . . . . 3 3 3 #> 10 . . . . . . 1 2 3 8 9 10 #> 11 . . . . . . 1 2 3 9 10 11 #> 12 . . . . . . 1 2 3 10 11 12 #>