rm(list = ls()) # indices for fitting glm row=c(1,1,1,2,2,2,3,3,3) col=c(1,2,3,1,2,3,1,2,3) row=factor(row) col=factor(col) # These are the 12 tables # I read them in by row t1=c(1,0,0,0,0,2,0,2,1) t2=c(1,0,0,0,1,1,0,1,2) t3=c(1,0,0,0,2,0,0,0,3) t4=c(0,0,1,0,0,2,1,2,0) t5=c(0,0,1,0,1,1,1,1,1) t6=c(0,0,1,0,2,0,1,0,2) t7=c(0,1,0,0,0,2,1,1,1) t8=c(0,1,0,0,1,1,1,0,2) t9=c(0,0,1,1,0,1,0,2,1) t10=c(0,0,1,1,1,0,0,1,2) t11=c(0,1,0,1,1,0,0,0,3) t12=c(0,1,0,1,0,1,0,1,2) # "matrix" reads by column # so they need to be transposed # for each group of three commands # first fits the model in glm to compute G^2 # second fits the model in chisq.test to compute X^2 # then prints out the numbers X^2, G^2 fit1 = glm(t1 ~ row + col, poisson) f1=chisq.test(t(matrix(t1,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t2 ~ row + col, poisson) f1=chisq.test(t(matrix(t2,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t3 ~ row + col, poisson) f1=chisq.test(t(matrix(t3,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t4 ~ row + col, poisson) f1=chisq.test(t(matrix(t4,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t5 ~ row + col, poisson) f1=chisq.test(t(matrix(t5,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t6 ~ row + col, poisson) f1=chisq.test(t(matrix(t6,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t7 ~ row + col, poisson) f1=chisq.test(t(matrix(t7,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t8 ~ row + col, poisson) f1=chisq.test(t(matrix(t8,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t9 ~ row + col, poisson) f1=chisq.test(t(matrix(t9,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t10 ~ row + col, poisson) f1=chisq.test(t(matrix(t10,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t11 ~ row + col, poisson) f1=chisq.test(t(matrix(t11,3,3)),correct=F) c(f1$stat,fit1$dev) fit1 = glm(t12 ~ row + col, poisson) f1=chisq.test(t(matrix(t12,3,3)),correct=F) c(f1$stat,fit1$dev)