I'm trying to understand how the equations (respecting indices) and the variance and covariance matrices of some mixed models adjusted in R are expressed, which are initially expressed by the lme4 and nlme packages.
The first model is a model of just one random effect on the intercept, this one doesn't seem difficult to me.
Adjusted for example as follows in lme4 and nlme respectively:
# Var6 it's a qualitative variable.
# Var7 it's a qualitative variable.
modA_lmer <- lmer(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5)+(1|Var6), data)
modA_lme <- lme(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5),
random = ~1|Var6, data)
modB_lmer <- lmer(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5)+(1|Var7), data)
modB_lme <- lme(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5),
random = ~1|Var7, data)
modC_lmer <- lmer(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5)+(1|Var6)+(1|Var7), data)
modC_lme <- lme(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5),
random= list(Var8= pdIdent(form = ~ 0 + as.factor(Var6)),
Var7 = ~1), data)
I'm not sure (would it be possible for someone to check? Mainly indexes.), but I think that the equation of the three models, respecting the indices, would be given by:
I believe that the variance and covariance matrices D of the random effects would be expressed by
Ok, assuming that everything described above is correct, now imagine the mixed model B in a heterocedastic case, assuming different variances per level of a dummy variable Var 8, which adjusted through the lme4 and nlme packages would look like:
# Var 8 it's a dummy variable
modD_lmer <- lmer(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5)+(Var8-1||Var6), data)
modD_lme <- lme(log(Var1)~log(Var2)+log(Var3)+
(Var4)+(Var5),
random = list(Var6=pdDiag(~Var8)), data)
In this case, what would the equation of my model look like? I thought of the following situation:
Is this correct? The equation would be exactly the same but the difference would be the introduction of an index in the sigma^2 of the error?
The other question is, well, in this case, how would the matrix of variances and covariances look like? Would I have three sigmas in the diagonal matrix? I.e:
I found some information in :



