# Loglinear Models" In vcdExtra: 'vcd' Extensions and Additions

Rscore <- as.numeric(Mental$mental)  Then, the row effects model, the column effects model, and the uniform association model can be fit as follows: # column effects model (ses) coleff <- glm(Freq ~ mental + ses + Rscore:ses, family = poisson, data = Mental) # row effects model (mental) roweff <- glm(Freq ~ mental + ses + mental:Cscore, family = poisson, data = Mental) # linear x linear association linlin <- glm(Freq ~ mental + ses + Rscore:Cscore, family = poisson, data = Mental)  The LRstats() function in vcdExtra provides a nice, compact summary of the fit statistics for a set of models, collected into a glmlist object. Smaller is better for AIC and BIC. # compare models using AIC, BIC, etc vcdExtra::LRstats(glmlist(indep, roweff, coleff, linlin))  For specific model comparisons, we can also carry out tests of nested models with anova() when those models are listed from smallest to largest. Here, there are two separate paths from the most restrictive (independence) model through the model of uniform association, to those that allow only one of row effects or column effects. anova(indep, linlin, coleff, test="Chisq") anova(indep, linlin, roweff, test="Chisq")  The model of linear by linear association seems best on all accounts. For comparison, one might try the CMH tests on these data: CMHtest(xtabs(Freq~ses+mental, data=Mental))  ## Non-linear terms The strength of the gnm package is that it handles a wide variety of models that handle non-linear terms, where the parameters enter the model beyond a simple linear function. The simplest example is the Goodman RC(1) model [@Goodman:79], which allows a multiplicative term to account for the association of the table variables. In the notation of generalized linear models with a log link, this can be expressed as $$\log \mu_{ij} = \alpha_i + \beta_j + \gamma_{i} \delta_{j} ,$$ where the row-multiplicative effect parameters$\gamma_i$and corresponding column parameters$\delta_j\$ are estimated from the data.% ^[This is similar in spirit to a correspondence analysis with a single dimension, but as a statistical model.]

Similarly, the RC(2) model adds two multiplicative terms to the independence model,

$$\log \mu_{ij} = \alpha_i + \beta_j + \gamma_{i1} \delta_{j1} + \gamma_{i2} \delta_{j2} .$$

In the gnm package, these models may be fit using the Mult() to specify the multiplicative term, and instances() to specify several such terms.

Example: For the Mental data, we fit the RC(1) and RC(2) models, and compare these with the independence model.

RC1 <- gnm(Freq ~ mental + ses + Mult(mental,ses), data=Mental,
family=poisson, verbose=FALSE)
RC2 <- gnm(Freq ~ mental+ses + instances(Mult(mental,ses),2), data=Mental,
family=poisson, verbose=FALSE)
anova(indep, RC1, RC2, test="Chisq")


## Try the vcdExtra package in your browser

Any scripts or data that you put into this service are public.

vcdExtra documentation built on April 21, 2022, 5:10 p.m.