Last active
August 29, 2015 13:56
-
-
Save baogorek/9145934 to your computer and use it in GitHub Desktop.
Three variations of the same nested model in lmer. See http://lme4.r-forge.r-project.org/book/Ch2.pdf for more detail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lme4) | |
head(Pastes) | |
# three casks are nested within each of 10 batches. | |
# No cask is used twice! (30 total casks) | |
# Noted that the variable "sample" is a concatination of "batch" and "cask" | |
lmer1 <- lmer(strength ~ 1 + (1 | batch) + (1 | sample), Pastes, REML=F) | |
lmer2 <- lmer(strength ~ 1 + (1 | batch) + (1 | batch:cask), Pastes, REML=F) | |
lmer3 <- lmer(strength ~ 1 + (1 | batch/cask), Pastes, REML = F) | |
summary(lmer1) | |
summary(lmer2) | |
summary(lmer3) | |
# Leaving out the main effect of batch, notice how the batch:cask variance | |
# is the sum of the batch and batch:cask variance components from the lmer1-lmer3 | |
lmer2b <- lmer(strength ~ 1 + (1 | batch:cask), Pastes, REML=F) | |
summary(lmer2b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment