Skip to content
Prev 14496 / 20628 Next

extract level 2 residuals of merMod from lme() and test for spatial autocorrelation.

Thanks very much.

Yes, that was a typo. I'm working with lme4 and the lmer function to make
merMod objects. Sorry for any confusion.

Here is a reproducible example of my attempt to extract residuals at the
population level (ie random effects) by subtracting predictions from
observations.

library(lme4)
fm1 <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy) # load library,
fit merMod object

test <- sleepstudy$Reaction - (predict(fm1, re.form= ~ (1| Subject))) #
subtract predictions from observations

summary(fm1) # examine residuals of random effects, which provides:
# "Residual              960.5   30.99 " for variance and std dev,
respectively
var(test); sd(test) # which provides 869.8171 and 29.49266

# test <- sleepstudy$Reaction - (predict(fm1, re.form= NULL)) #
unsurprisingly has same results as above

960.5 <> 869.8171 and 30.99 <> 29.49266 although they are the same
direction and order of magnitude. I'm finding similar results with my
actual data and model fits.

Any advice is appreciated, thanks again!
Dexter
On Sat, May 7, 2016 at 2:03 PM, Ben Bolker <bbolker at gmail.com> wrote: