> chisq.test(matrix(c(279, 73, 225, 165, 47, 191), ncol = 3, byrow = T)) Pearson's chi-square test without Yates' continuity correction data: matrix(c(279, 73, 225, 165, 47, 191), ncol = 3, byrow = T) X-squared = 7.0095, df = 2, p-value = 0.0301 > data <- read.table("gendergap.dat", header= T) # read separate file > data gender party count 1 female d 279 2 female i 73 3 female r 225 4 male d 165 5 male i 47 6 male r 191 > attach(data) > gendergap.fit <- glm(count ~ gender + party, family = poisson(link=log), resid = "pearson") # generalized lin. model for log count > gendergap.fit Call: glm(formula = count ~ gender + party, family = poisson(link = log), resid = "pearson") Coefficients: (Intercept) gender party1 party2 4.928837 -0.1794529 -0.6541664 0.1963424 Degrees of Freedom: 6 Total; 2 Residual Residual Deviance: 7.002594 > 1 - pchisq(7.0026, 2) # P-value [1] 0.03015815 > expected <- fitted(gendergap.fit) # estimated expected frequencies > residual <- (count - expected)/sqrt(expected) # Pearson residuals > count; expected; residual 1 2 3 4 5 6 279 73 225 165 47 191 > 1 2 3 4 5 6 261.4163 70.65306 244.9306 182.5837 49.34694 171.0694 > 1 2 3 4 5 6 1.087535 0.2792134 -1.2735 -1.301304 -0.3340963 1.523823 > matrix(c(count,expected,residual),ncol=3) [,1] [,2] [,3] [1,] 279 261.41633 1.0875350 [2,] 73 70.65306 0.2792134 [3,] 225 244.93061 -1.2735005 [4,] 165 182.58367 -1.3013036 [5,] 47 49.34694 -0.3340963 [6,] 191 171.06939 1.5238229 > count2 <- c(279,73,165,47) # Next show decomposition of G-squared > party2 <- scan(,"") 1: d 2: i 3: d 4: i 5: > gender2 <- scan(,"") 1: f 2: f 3: m 4: m 5: > fit2 <- glm(count2 ~ party2+gender2, family=poisson(link=log)) > fit2 Degrees of Freedom: 4 Total; 1 Residual Residual Deviance: 0.1611715 > count3 <- c(352, 225, 212, 191) > fit3 <- glm(count3 ~ party2+gender2, family=poisson(link=log)) > fit3 Degrees of Freedom: 4 Total; 1 Residual Residual Deviance: 6.841422