################
# Normal Model #
################
cake$repbatch<-100*cake$Replicate+cake$Batch
R1Cake<-data.frame(int=rep(1,15))
R2Cake<-data.frame(int=rep(1,45))
modCake1<-HGLMfit(DistResp="Normal",DistRand=c("Normal","Normal"),Link="Identity",LapFix=FALSE,ODEst=TRUE,ODEstVal=c(0),
formulaMain=Angle~as.factor(Recipe)+as.factor(Temperature)+as.factor(Recipe)*as.factor(Temperature)+(1|Replicate)+(1|repbatch),
,formulaOD=~1,formulaRand=list(one=~1,two=~1),
DataMain=cake,DataRand=list(R1Cake,R2Cake),Offset=NULL,BinomialDen=rep(1,360),
,INFO=TRUE,DEBUG=FALSE)
# Creating residual plots for the normal-normal-normal model #
# postscript("V:\\HomeDir\\576790\\EUR\\ZIPHGLM_Package\\Paper_JSS\\graphs\\cakeG1.eps",horiz=TRUE)
op<-par(mfrow=c(2,2),
oma = c(1,1,2,1),
mar = c(3,3,4,1) +1.2 # Margins
)
res<-modCake1$Details$StdDevianceResidualY
# Scaled fitted values vs residuals #
xmat<-model.matrix(~as.factor(Recipe)+as.factor(Temperature)+as.factor(Recipe)*as.factor(Temperature),data=cake)
mu<-xmat%*%modCake1$Results$Beta
plot(mu,res,pch=18,col="black",xlab="Scaled Fitted Values",ylab="Deviance Residuals")
los<-loess.smooth(mu, res, span = 1/2, degree = 1,
family = c("symmetric", "gaussian"), evaluation = 50)
lines(los$x,los$y,col="black",lwd=2)
# Scaled fitted values vs absolute residuals #
plot(mu,abs(res),pch=18,col="black",xlab="Scaled Fitted Values",ylab="Absolute Deviance Residuals")
los<-loess.smooth(mu, abs(res), span = 1/2, degree = 1,
family = c("symmetric", "gaussian"), evaluation = 50)
lines(los$x,los$y,col="black",lwd=2)
# qqplot #
qqnorm(res,pch=18)
abline(h=0,v=0)
abline(a=0,b=1,lty=3)
# histogram of residuals #
breaks<-seq(-4,4,by=0.8)
hist(res,breaks=breaks,xlab="Deviance Residuals",main="Histogram")
par(op)
mtext("Diagnostics for Cake Model Normal",
side=3, line=1.5, font=2, cex=2, col='black')
par(op)
# dev.off()