Is it possible to fit multivariate Gaussian models implied by mixed-models through generalised least squares in R, by using, for instance, the gls function?
For instance, the random intercept model via lme is
mod.lme <- lme(score~Machine, random = ~1|Worker, data=Machines)
s2.lme <- as.numeric(VarCorr(mod.lme)[2,1]) #residual variance
s2.ranef.lme <- as.numeric(VarCorr(mod.lme)[1,1]) # ran. eff. variance
(tot.var.lme <- s2.lme + s2.ranef.lme) # sum of variance components
The corresponding Gaussian model can be fitted by gls as follows:
mod.gls <- gls(score~Machine, correlation = corCompSymm(form = ~1| Worker),
data=Machines)
(tot.var.gls <- as.numeric(exp(attributes(mod.gls$apVar)$Pars[2]))^2)
mSt <- mod.gls$modelStruct
cSt <- mSt$corStruct
(rho <- coef(cSt, unconstrained = FALSE))
all.equal(tot.var.gls, tot.var.lme) # total variances equal?
s2.ranef.gls <- rho*tot.var.gls # get variance of the ran. eff from gls
all.equal(as.numeric(s2.ranef.gls), s2.ranef.lme) # is equal to lme ?
But what about this ?
mod2.lme <- lme(score~Machine, random = ~1|Worker/Machine, data = Machines)
How would you fit it by gls ? Is it possible ?
glsis then able to parameterize that model is then the next question. I haven't worked out the math, so I don't know, but my guess is that you may have to write your owncorStructclass if you need to usegls. – Rune H Christensen May 23 '18 at 06:22Machinesdata it is actually not the case thatMachineis nested inWorker- rather, these variables are crossed. In fact the last model "tricks"lmeto fit a model with a random main effect ofWorkerand the random interaction forWorker:Machine. Was that intentional? – Rune H Christensen May 23 '18 at 06:47corStructclass in order to fit it withgls? (2) If you have a particular and not any mixed-model in mind, please specify it. For a general (any) mixed model of the form $Y = X\beta + Z b + e$ with $e \sim MVN(0, R)$ and $b \sim MVN(0, G)$ we have $Cov(Y) = Z G Z' + R$ which does not simplify and therefore infeasible to fit withgls. Some structure is needed. – Rune H Christensen May 23 '18 at 11:16