library(ISwR)
kfm
kfm$Sex=factor(kfm$sex,level=c("boy","girl"),label=c(0,1))
kfm$Sex
kfm
g.fullmodel=lm(dl.milk~Sex*weight*ml.suppl*mat.weight*mat.height,data=kfm)
summary(g.fullmodel)
g=lm(dl.milk~Sex+weight+ml.suppl+mat.weight+mat.height,data=kfm)
summary(g)
g2=update(g,.~.-mat.weight,data=kfm)
summary(g2)
g3=update(g2,.~.-Sex,data=kfm)
summary(g3)

g4=update(g3,.~.-ml.suppl,data=kfm)
summary(g4)


anova(g,g4)

par(mfrow=c(1,2))
plot(dl.milk~mat.height,pch=c(1,2)[Sex],col=c("blue","red")[Sex],data=kfm)
plot(dl.milk~weight,pch=c(1,2)[Sex],col=c("blue","red")[Sex],data=kfm)

res=rstandard(g4)
attach(kfm)
opar=par(mfrow=c(2,2),mex=0.6)
plot(weight,res,col="green")
abline(0,0,col="red")
plot(mat.height,res,col="purple")
abline(0,0,col="red")
plot(fitted(g4),res,col="blue")
abline(0,0,col="red")
qqnorm(res,col="darkgreen")
qqline(res,col="red")


