-
The only mistake people made was an assumption that if year is significant
and corps is significant, than model with year and
corps is significant. Usually this is true, but not always,
and in this home work you were specifically asked to "Test the hypothesis
that neither year or corps is significant in predicting the number of deaths".
-
No general problems here.
A few people try to run loops of 10 -30 iterations which is a good
idea, but running it till convergence in deviance is better idea, and only
one person did it. In any case, you HAVE TO CHECK IF CONVERGENCE ACHIEVED.
Here is my version of that loop:
data<-read.table(file="/afs/stat.lsa.umich.edu/users/faculty/faraway/.public_html/data/horsekick.data",header=T)
attach(data,pos=1)
y<-deaths
mu<-y
fit<-lm(log(mu)~year + corps,weights=mu)
fit.dif<-fit$fit*0+1
while(sum(abs(round(fit.dif,2)))>0){
fit.old<-fit$fit
z<-fit$fitted+(y-exp(fit$fitted))/exp(fit$fitted)
w<-exp(fit$fitted)
fit<-lm(z~year + corps,weights=w)
fit.dif<-fit.old-fit$fit
print(sum((fit$fit)*y-exp(fit$fit)-gamma(y+1)))
cat("\n")
}
fit.glm<-glm(y~year+corps,family=poisson)
fit$coef
fit.glm$coef
sum(abs(fit.glm$coef-fit$coef))
sum((fit$fit)*y-exp(fit$fit)-gamma(y+1))
sum(log(fit.glm$fit)*y-fit.glm$fit-gamma(y+1))
Note that I used data file located in Pf. J. Faraway directory, and
didn't make another copy of it. Also I didn't have to add 0.1 to
log(mu) because I put log(mu) right in to the model, and Splus assign weight
0 to all NAs.