Let consider this simple model consisting in two independent random effects:
$$y_{ijk} = \mu + \delta1_i + \delta2_j + \epsilon_{i,j,k}$$
where \delta1_i
and \delta2_j
are independent random effect (i.e. \delta1_i \sim N(0,\sigma_1^2)
iid, \delta2_i \sim N(0,\sigma_1^2)
iid, both independent).
Defining and inferring the variance components of such a model is straightforward using lme4::lmer (sorry the example below is likely to have no physical meaning) :
library(lme4)
library(nlme)
data(Orthodont,package="nlme")
lmer(data=Orthodont,distance~1+(1|Sex)+(1|Subject))
#Linear mixed model fit by REML ['lmerMod']
#Formula: distance ~ 1 + (1 | Sex) + (1 | Subject)
# Data: Orthodont
#REML criterion at convergence: 510.3937
#Random effects:
# Groups Name Std.Dev.
# Subject (Intercept) 1.596
# Sex (Intercept) 1.550
# Residual 2.220
#Number of obs: 108, groups: Subject, 27; Sex, 2
#Fixed Effects:
#(Intercept)
# 23.83
How can this be modeled easily using nlme::lme ? Specifying the random effect using a list of random effect implicitly introduces interaction depending from the ordering of the random effects , which can be verified here (changing order of specification, change results):
VarCorr(lme(data=Orthodont,distance~1,random=list(~1|Subject,~1|Sex)))
# Variance StdDev
#Subject = pdLogChol(1)
#(Intercept) 1.875987 1.369667
#Sex = pdLogChol(1)
#(Intercept) 1.875987 1.369667
#Residual 4.929784 2.220312
VarCorr(lme(data=Orthodont,distance~1,random=list(~1|Sex,~1|Subject)))
# Variance StdDev
#Sex = pdLogChol(1)
#(Intercept) 2.403699 1.550387
#Subject = pdLogChol(1)
#(Intercept) 2.546702 1.595839
#Residual 4.929784 2.220312