[R] contingency table analysis; generalized linear model

Mark Difford mark_difford at yahoo.co.uk
Tue Jan 9 12:13:41 CET 2007

Dear List,

I would appreciate help on the following matter:

I am aware that higher dimensional contingency tables can be analysed using either log-linear models or as a poisson regression using a generalized linear model:

loglm(~Age+Site, data=xtabs(~Age+Site, data=SSites.Rev, drop.unused.levels=T))

glm.table <- as.data.frame(xtabs(~Age+Site, data=SSites.Rev, drop.unused.levels=T))
glm(Freq ~ Age + Site, data=glm.table, family='poisson')

where Site is a factor and Age is cast as a factor by xtabs() and treated as such.

Is it acceptable to step away from contingency table analysis by recasting Age as a numerical variable, and redoing the analysis as:

glm(Freq ~ as.numeric(Age) + Site, data=glm.table, family='poisson')

My reasons for wanting to do this are to be able to include non-linear terms in the model, using say restricted or natural cubic splines.

Thank you in advance for your help.
Mark Difford.

Mark Difford
Ph.D. candidate, Botany Department,
Nelson Mandela Metropolitan University,
Port Elizabeth, SA.

More information about the R-help mailing list