Skip to content

Estimating variance in linear mixed models

3 messages · Maggie Neff, Andrew Miles, Ista Zahn

#
A linear multilevel model like you are using can be used to estimate the between-year variance, like so (note I'm using the lmer function, not lme, which I am less familiar with):

library(lme4)
mod=lmer(cont ~ 1 + (1|year), data=fish)

The Random Effects for (Intercept) will give you the variance of the estimates of contaminants in each year.  However, with only 9 different years (and hence 9 different estimates of contaminants), the random effect might not be very reliable.  You can get model predicted estimates for each of the years like so:
coef(mod)

I can't immediately think of a way to estimate within-year variance using a MLM, but you could get estimates of the within-year variance doing something like this:
tapply(cont, year, var)

This should break down cont by year, and then estimate the variance in each year.

I hope this helps.

Andrew Miles
On Feb 1, 2012, at 1:54 PM, Maggie Neff wrote:

            
#
Hi Andrew and Maggie,
On Wednesday, February 01, 2012 03:31:05 PM Andrew Miles wrote:
The residual variance from the lmer model is the within-year variance, no?