babies <- read.table("babies.data", header=TRUE, ) babies <- babies[babies[,"smoke"] != 9,] attach(babies) prem = factor(as.numeric(gestation < 7*37)) babies <- cbind(babies, prem) model1 <- glm(prem ~ bwt, family = binomial, data = babies) summary(model1) model2 <- glm(prem ~ bwt + age, family = binomial, data = babies) summary(model2) anova(model1, model2, test="Chisq") model3 <- glm(prem ~ age, family = binomial, data = babies) summary(model3) model4 <- glm(prem ~ age + smoke, family = binomial, data = babies) summary(model4) anova(model1, model4, test="Chisq") pres1 = residuals(model1, type='pearson') dres1 = residuals(model1, type='deviance') par(mfrow=c(2,2)) hist(dres1) hist(pres1) plot(dres1, pres1) plot(predict(model1), dres1) plot(model1)