For the Oats
dataset in nlme
, page 162 of "Mixed-effects models in S and S-PLUS" provided a way to express multilevel model through single-level expression in nlme
.
More specifically, the following is a multilevel model in which Variety
is nested in Block
specified in the conventional way:
library(nlme)
fm4Oats <- lme( yield ~ nitro, data = Oats, random = ~ 1 | Block/Variety )
Page 162 of "Mixed-effects models in S and S-PLUS" provided the following alternative fitting strategy through single-level representation of the mixed model (R code highlighted in green, math formula also included to facilitate understanding):
I wish ask how to write the code through single-level expression approach (like fm4OatsC
) if I want to add a covariate whose random slope effect varies across levels of Variety and additionally assume a compound covariance structure between random intercept and random slope. More specifically, I want the covariance matrix (Psi**_new
) to be as follows:
where
sigma^2_1
and sigma^2_2
are the same as in the book, and sigma^2_3
is the variance for the random slope of covariate x
, and sigma_23
is the covariance between random intercept of Variety and random slope of x
.
Note: There is no covariate x
in the Oats
data. I just wish to see how the formula should have been written in nlme
to specify the designated psi**_new
.
I like the single-level expression approach since it allows for more flexibility in defining the covariance structure. But I also wish to know if the following code gives the desired covariance matrix:
fm4Oats <- lme( yield ~ nitro, data = Oats, random = ~ x | Block/Variety )