Thu Nov 18 09:30:10 2004 ======================== > print(table8.3 <- read.table("table8-3.txt",header=T)) a c m n 1 1 1 1 911 2 1 1 2 538 3 1 2 1 44 4 1 2 2 456 5 2 1 1 3 6 2 1 2 43 7 2 2 1 2 8 2 2 2 279 =============================================================== > attach(table8.3) > X <- ifelse(a==1,1,0) > Y <- ifelse(c==1,1,0) > Z <- ifelse(m==1,1,0) > detach() > summary(fit.XYZ <- glm(n ~ X*Y*Z, data=table8.3,family=poisson)) Call: glm(formula = n ~ X * Y * Z, family = poisson, data = table8.3) Deviance Residuals: [1] 0 0 0 0 0 0 0 0 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 5.63121 0.05987 94.060 < 2e-16 *** X 0.49128 0.07601 6.464 1.02e-10 *** Y -1.87001 0.16383 -11.414 < 2e-16 *** Z -4.93806 0.70964 -6.959 3.44e-12 *** X:Y 2.03538 0.17576 11.580 < 2e-16 *** X:Z 2.59976 0.72698 3.576 0.000349 *** Y:Z 2.27548 0.92746 2.453 0.014149 * X:Y:Z 0.58951 0.94236 0.626 0.531600 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 2.8515e+03 on 7 degrees of freedom Residual deviance: -1.2590e-13 on 0 degrees of freedom AIC: 65.043 Number of Fisher Scoring iterations: 3 =================================================================== > table8.3$a <- as.factor(table8.3$a) > table8.3$c <- as.factor(table8.3$c) > table8.3$m <- as.factor(table8.3$m) > summary(fit.full <- glm(n ~ a*c*m,data=table8.3,family=poisson)) Call: glm(formula = n ~ a * c * m, family = poisson, data = table8.3) Deviance Residuals: [1] 0 0 0 0 0 0 0 0 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 6.81454 0.03313 205.682 < 2e-16 *** a2 -5.71593 0.57830 -9.884 < 2e-16 *** c2 -3.03035 0.15435 -19.633 < 2e-16 *** m2 -0.52668 0.05437 -9.686 < 2e-16 *** a2:c2 2.62489 0.92583 2.835 0.00458 ** a2:m2 3.18927 0.59962 5.319 1.04e-07 *** c2:m2 2.86499 0.16696 17.159 < 2e-16 *** a2:c2:m2 -0.58951 0.94236 -0.626 0.53160 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 2.8515e+03 on 7 degrees of freedom Residual deviance: -4.1522e-14 on 0 degrees of freedom AIC: 65.043 Number of Fisher Scoring iterations: 3 > options()$contrasts unordered ordered "contr.treatment" "contr.poly" > help(contr.treatment) > model.matrix(fit.full) (Intercept) a2 c2 m2 a2:c2 a2:m2 c2:m2 a2:c2:m2 1 1 0 0 0 0 0 0 0 2 1 0 0 1 0 0 0 0 3 1 0 1 0 0 0 0 0 4 1 0 1 1 0 0 1 0 5 1 1 0 0 0 0 0 0 6 1 1 0 1 0 1 0 0 7 1 1 1 0 1 0 0 0 8 1 1 1 1 1 1 1 1 > model.matrix(fit.XYZ) (Intercept) X Y Z X:Y X:Z Y:Z X:Y:Z 1 1 1 1 1 1 1 1 1 2 1 1 1 0 1 0 0 0 3 1 1 0 1 0 1 0 0 4 1 1 0 0 0 0 0 0 5 1 0 1 1 0 0 1 0 6 1 0 1 0 0 0 0 0 7 1 0 0 1 0 0 0 0 8 1 0 0 0 0 0 0 0 > XX <- 1-X; YY <- 1-Y; ZZ <- 1-Z > t(t(glm(n ~ XX*YY*ZZ, data=table8.3,family=poisson)$coeff)) [,1] (Intercept) 6.8145429 XX -5.7159306 YY -3.0303533 ZZ -0.5266843 XX:YY 2.6248882 XX:ZZ 3.1892722 YY:ZZ 2.8649875 XX:YY:ZZ -0.5895107 > old.contrasts <- options()$contrasts > contr.dummy <- function(...) {contr.treatment(...,base=2) } > options(contrasts=c("contr.dummy","contr.poly")) > t(t(glm(n ~ a*c*m, data=table8.3,family=poisson)$coeff)) [,1] (Intercept) 5.6312118 a1 0.4912810 c1 -1.8700117 m1 -4.9380646 a1:c1 2.0353774 a1:m1 2.5997614 c1:m1 2.2754768 a1:c1:m1 0.5895107 > model.matrix(glm(n ~ a*c*m, data=table8.3,family=poisson)) (Intercept) a1 c1 m1 a1:c1 a1:m1 c1:m1 a1:c1:m1 1 1 1 1 1 1 1 1 1 2 1 1 1 0 1 0 0 0 3 1 1 0 1 0 1 0 0 4 1 1 0 0 0 0 0 0 5 1 0 1 1 0 0 1 0 6 1 0 1 0 0 0 0 0 7 1 0 0 1 0 0 0 0 8 1 0 0 0 0 0 0 0 > options(contrasts=old.contrasts) ==================================================================== > summary(fit.n3w <- glm(n ~ a*c*m - a:c:m,data=table8.3,family=poisson)) > summary(fit.acgm <- glm(n ~ a*m + c*m, data=table8.3,family=poisson)) ====================================================================