data(Mental)
str(Mental)
(Mental.tab <- xtabs(Freq ~ ses + mental, data=Mental))
# mosaic and sieve plots
mosaic(Mental.tab, gp=shading_Friendly)
sieve(Mental.tab, gp=shading_Friendly)
if(require(ca)){
plot(ca(Mental.tab), main="Mental impairment & SES", lines=TRUE)
}
# fit linear x linear (uniform) association model, using integer scores
# for rows/cols
indep <- glm(Freq ~ mental + ses, family = poisson, data = Mental)
Cscore <- as.numeric(Mental$ses)
Rscore <- as.numeric(Mental$mental)
linlin <- glm(Freq ~ mental + ses + Rscore:Cscore,
family = poisson, data = Mental)
anova(linlin, test = "Chisq")
# use update.glm method to fit other models
linlin <- update(indep, . ~ . + Rscore:Cscore)
roweff <- update(indep, . ~ . + mental:Cscore)
coleff <- update(indep, . ~ . + Rscore:ses)
rowcol <- update(indep, . ~ . + Rscore:ses + mental:Cscore)
# compare models
LRstats(indep, linlin, roweff, coleff, rowcol)
# tests of nested models
anova(indep, linlin, roweff, test = "Chisq")
Run the code above in your browser using DataLab