Skip to content
Prev 16509 / 20628 Next

CANNOT PARTITION ERROR VARIANCE AMONG EXPERIMENTS

Hi Kassim,

fit <- lmer(yield~Experiment+(1|Genotype), data = MET)

# variance "explained" by fixed effects, i.e. between experiments
fitval <- model.matrix(fit) %*% fixef(fit)
n <- length(fitval)
Vf <- sum((fitval - mean(fitval))^2)/n
#  var(fitval) would be simpler but uses n-1 as the denominator whereas I think (?!) n is correct
# (in practice it'll only make a substantial difference if n is very small)

# genotype random effect variance (unexplained variation among genotypes)
Vr <- VarCorr(fit)$Genotype[, ]
# (note that this doesn't work when there are random slopes)

# residual/error variance (unexplained variation between observations)
Ve <- attr(VarCorr(fit), "sc")^2

var(MET$yield)
# ...should be not too far from
Vf + Vr + Ve

Best wishes,
Paul