[R] Fixed zeros in tables

A.R. Criswell rstatistics at gmail.com
Sun Nov 26 05:39:39 CET 2006


Hello All R Users,

Function loglm() in library MASS can be cajoled to accomodate
structural zeros in a cross-classification table. An example from
Fienberg demonstrates how this can be done.

My question is: Can the function glm() perform the same task? Can
glm() estimate a log-linear model with fixed zeros like loglm()?

Thanks for your help,
Andrew

## Fienberg, The Analysis of Cross-Classified Contingency Tables, 2nd
ed., p.148.
## Results from survey of teenagers regarding their health concerns.

health <- data.frame(expand.grid(CONCERNS = c("sex", "menstral",
                                              "healthy", "nothing"),
                                 AGE      = c("12-15", "16-17"),
                                 GENDER   = c("male", "female")),
                                 COUNT    = c(4, 0, 42, 57, 2, 0, 7, 20,
                                              9, 4, 19, 71, 7, 8, 10, 21))

health <- xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = health)

zeros <- data.frame(expand.grid(CONCERNS = c("sex", "menstral",
                                              "healthy", "nothing"),
                                AGE      = c("12-15", "16-17"),
                                GENDER   = c("male", "female")),
                                COUNT    = c(1, 0, 1, 1, 1, 0, 1, 1,
                                             1, 1, 1, 1, 1, 1, 1, 1))

zeros <- xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = zeros)

library(MASS)

fm.1 <- loglm(~ CONCERNS + AGE + GENDER,
              data = health, start = zeros, fitted = TRUE)

fm.1; round(fm.1$fitted, 1)



More information about the R-help mailing list