Skip to content
Prev 4432 / 5636 Next

[R-meta] residuals in lmer versus rma.mv

Hi Martin,

For rma.mv(), you should use:

m.rma <- rma.mv(Y  ~ X,
                V=0, random = list(~ 1|Paper/PubID, ~ 1|ID),
                R=list(ID = Rmat), Rscale=FALSE,
                data=dat, method = "REML", digits=5, sparse = TRUE)

But you still won't get the same residuals, because residuals(m.lmer) computes 'conditional residuals' (Y minus 'fitted values based on the fixed effects plus random effects'), while residuals(m.rma) computes 'marginal residuals' (Y minus 'fitted values based on the fixed effects').

For 'rma.uni' models, rstandard(<model>, type="conditional") also computes conditional residuals, but I have not yet implemented this for 'rma.mv' models. But you can get these manually as follows:

dat$`Paper/PubID` <- paste0(dat$Paper, "/", dat$PubID)
re <- ranef(m.rma)
Res.rma <- dat$Y - (fitted(m.rma) +
re$`Paper`$intrcpt[match(dat$`Paper`, row.names(re$Paper))] + 
re$`Paper/PubID`$intrcpt[match(dat$`Paper/PubID`, row.names(re$`Paper/PubID`))])
head(Res.rma)

The minor differences arise due to slightly different parameter estimates, but that can be ignored.

If you install the 'devel' version, you can do the slightly simpler:

re <- ranef(m.rma, expand=TRUE)
Res.rma <- dat$Y - (fitted(m.rma) + re$`Paper`$intrcpt + re$`Paper/PubID`$intrcpt)
head(Res.rma)

(note that the 'expand' argument is not currently documented).

Best,
Wolfgang