Suppose I have 10 students, who each attempt to solve 20 math problems. The problems are scored correct or incorrect (in longdata) and each student's performance can be summarized by an accuracy measure (in subjdata). Models 1, 2, and 4 below appear to produce different results, but I understand them to be doing the same thing. Why are they producing different results? (I included model 3 for reference.)
library(lme4)
set.seed(1)
nsubjs=10
nprobs=20
subjdata = data.frame('subj'=rep(1:nsubjs),'iq'=rep(seq(80,120,10),nsubjs/5))
longdata = subjdata[rep(seq_len(nrow(subjdata)), each=nprobs), ]
longdata$correct = runif(nsubjs*nprobs)<pnorm(longdata$iq/50-1.4)
subjdata$acc = by(longdata$correct,longdata$subj,mean)
model1 = lm(logit(acc)~iq,subjdata)
model2 = glm(acc~iq,subjdata,family=gaussian(link='logit'))
model3 = glm(acc~iq,subjdata,family=binomial(link='logit'))
model4 = lmer(correct~iq+(1|subj),longdata,family=binomial(link='logit'))
library(betareg)
model5 = betareg(acc~scale(iq),subjdata)
$\endgroup$ – user20061 Jan 25 '13 at 6:42library(car)
is necessary, for the logit function. $\endgroup$ – user20061 Jan 25 '13 at 17:53