foo <- read.table("squirrel.txt", header = TRUE) foo bar <- xtabs(count ~ active + passive, data = foo) bar # Distribution of genital display in a colony of six squirrel monkeys, # as reported by Ploog (1967), taken from Fienberg (1980, The Analysis # of Cross-Classified Categorical Data, MIT Press), Table 8-2. # diagonal elements are "structural zeros" or "fixed zeros" # (monkeys do not display to themselves -- the don't have mirrors) # xtabs apparently does not have this concept # we can fit this with loglin by specifying starting values that have # zero on the diagonal sss <- (bar + 1)^0 diag(sss) <- 0 sss lout <- loglin(bar, list(1, 2), start = sss, fit = TRUE) lout # loglin gets the fit right, I think, but does not count the structural # zeros correctly # OTOH, glm has no problem (because the structural zeros just are not # there in the data to confuse it. gout <- glm(count ~ active + passive, family = poisson, data = foo) sout <- summary(gout) sout names(sout) sout$deviance sout$df.residual pchisq(sout$deviance, sout$df.residual, lower.tail = FALSE) # This does not get the right degrees of freedom either because of # "solutions at infinity". More on this later.