eatdis <- read.table("http://socserv.socsci.mcmaster.ca/jfox/Books/Applied-Regression-3E/datasets/Blackmore.txt",header=TRUE) names(eatdis) dim(eatdis) eatdis$logex <- log2(eatdis$exercise+.08333) eatdis$age8 <- eatdis$age - 8 eatdis$patient <- as.numeric(eatdis$group == "patient") eatdis$patage8 <- eatdis$patient*eatdis $age8 library(afex) # as with fixed effects, a random intercept is assumed unless explicitly ruled out # when both (1|subject) and (age8|subject) are included separately, they are modeled as being uncorrelated # this is the model from page 721 eatdis.afex1 <- mixed(logex ~ patient +age8 +patage8 +(age8|subject), data=eatdis) # this model eliminates the random intercept (and covariance between random effects) eatdis.afex2 <- mixed(logex ~ patient +age8 +patage8 +(-1 +age8|subject), data=eatdis) # this model eliminates the random slope (and covariance between random effects) eatdis.afex3 <- mixed(logex ~ patient +age8 +patage8 +(1|subject), data=eatdis)