# NOT RUN {
data(selfPacedReadingHeid)
# data validation
plot(sort(selfPacedReadingHeid$RT))
selfPacedReadingHeid = selfPacedReadingHeid[selfPacedReadingHeid$RT > 5 &
selfPacedReadingHeid$RT < 7.2,]
# fitting a mixed-effects model
require(lme4)
require(lmerTest)
require(optimx)
x = selfPacedReadingHeid[,12:15]
x.pr = prcomp(x, center = TRUE, scale = TRUE)
selfPacedReadingHeid$PC1 = x.pr$x[,1]
selfPacedReadingHeid.lmer = lmer(RT ~ RTtoPrime + LengthInLetters +
PC1 * Condition + (1|Subject) + (1|Word),
control=lmerControl(optimizer="optimx",optCtrl=list(method="nlminb")),
data = selfPacedReadingHeid)
summary(selfPacedReadingHeid.lmer)
# model criticism
selfPacedReadingHeid.lmerA = lmer(RT ~ RTtoPrime + LengthInLetters +
PC1 * Condition + (1|Subject) + (1|Word),
control=lmerControl(optimizer="optimx",optCtrl=list(method="nlminb")),
data = selfPacedReadingHeid[abs(scale(resid(selfPacedReadingHeid.lmer))) < 2.5, ])
qqnorm(resid(selfPacedReadingHeid.lmerA))
summary(selfPacedReadingHeid.lmerA)
# }
Run the code above in your browser using DataLab