options(contrasts=c("contr.treatment", "contr.poly")) h.glm <- glm(y/n ~ Rtreat + Blocker + Site * Time, family=binomial, weights=n, data=heartattack) anova(h.glm, test="Chisq") hglm.final <- glm(y/n ~ Rtreat + Blocker + Site , family=binomial, weights=n, data=heartattack) summary(hglm.final) anova(hglm.final) u <- resid(hglm.final, type="pearson") # The Pearson residuals are saved in u v <- resid(hglm.final, type="deviance") # The deviance residuals are saved in v sum(u^2) # The result is the Pearson X^2 statistic sum(v^2) # The result is the scaled deviance # commands used to prepare data heartattack$n <- heartattack[,1] + heartattack[,2] u <- c("active", "placebo") heartattack$Rtreat <- rep(u, 12) u <- c("Yes", "Yes", "No", "No") heartattack$Blocker <- rep(u, 6) u <- c(rep("Le12H", 4), rep("Mo12H", 4) ) heartattack$Time <- rep(u, 3) heartattack$Site <- c( rep("Anterior", 8), rep("Inferior", 8), rep("Other", 8)) # finally convert the column types to factors