Test Notes, 4/9/03 evening (1) > tstp1 <- array(c(90,100,210,90,40,170,20,160,120), dim=c(3,3)) > tstp1 [,1] [,2] [,3] [1,] 90 90 20 [2,] 100 40 160 [3,] 210 170 120 > tstp1eb <- matrix(c(80,320*c(100,210)/310, 60, 240*c(40,170)/210, 60, 240*c(160,120)/280), ncol=3) tstp1ea <- tstp1eb; tstp1ea[2:3,1] <- 320*c(3/8,5/8) tstp1e0 <- outer(c(.2,.3,.5),c(400,300,300),"*") > sum((tstp1-tstp1eb)^2/tstp1eb) [1] 53.6458 ### X^2 for Hb > sum((tstp1-tstp1ea)^2/tstp1ea) [1] 57.16667 ### so 57.1667-53.6458 = 3.5209 = X^2 for Ha vs Hb > sum((tstp1-tstp1e0)^2/tstp1e0) [1] 137.6389 ### so 137.6389-57.1667= 80.472 = X^2 for H0 vs Ha ### Respectively compare these test statistics with > pchisq(.95, c(2,1,1)) [1] 5.991465 3.841459 3.841459 ### Corresponding G^2 statistics: > 2*diff(c(0, sum(tstp1*log(tstp1/tstp1eb)), sum(tstp1*log(tstp1/tstp1ea)), sum(tstp1*log(tstp1/tstp1e0)))) [1] 60.7972 3.7118 78.0019 ### So only the 1st and third are significant. Dividing all counts by ### 5 also divides EACH of X^2 and G^2 by 5: > .Last.value/5 [1] 12.1594354 0.7423501 15.6003859 ### 1st & 2rd STILL significant (3) > nv <- sample(5:10, 60, replace=T) > Xv <- rexp(60) > Yv <- rbinom(60, nv, plogis(-1 + .2*Xv)) > sum(Yv) [1] 132 > sum(nv) [1] 458 > summary(summary(tmpglm)$deviance.resid) Min. 1st Qu. Median Mean 3rd Qu. Max. -2.25100 -0.72460 -0.10640 -0.05093 0.62530 2.72200 > summary(sqrt(nv/(tmpglm$fit*(1-tmpglm$fit)))*( + tmpglm$y-tmpglm$fit)) Min. 1st Qu. Median Mean 3rd Qu. Max. -1.87700 -0.68330 -0.10580 0.01181 0.64330 2.86800