library(MASS)
ucb <- loglm(~ (Admit + Gender + Dept)^2, data = UCBAdmissions)
drop1.loglm(ucb)
drop1.loglm(ucb, scope = "Admit:Gender") # test only a subset
drop1.loglm(ucb, abbrev = 4) # abbreviate factor names
names(attr(drop1.loglm(ucb), "models")) # the fitted models, for free
# data.frame + `Freq ~ ...` form works too, not just array/table data
data(DaytonSurvey, package = "vcdExtra")
DS <- loglm(Freq ~ (cigarette + alcohol + marijuana + sex + race)^2,
data = DaytonSurvey)
drop1.loglm(DS)
LRanova(ucb) # default baseline: mutual independence over Admit, Gender, Dept
# supply a specific (nested) baseline other than the default -- here, one
# that already includes Admit:Gender, so partial R^2 is now relative to a
# smaller remaining G^2 than the mutual-independence baseline above
partial_baseline <- loglm(~ Admit + Gender + Dept + Admit:Gender, data = UCBAdmissions)
LRanova(ucb, baseline = partial_baseline)
assoc_strength(ucb) # Cramer's V (default)
assoc_strength(ucb, method = "Cohen") # Cohen's w
# partial (conditional on Dept) vs. marginal association -- the small
# partial Admit:Gender V here versus the much larger marginal V below is
# the classic Simpson's-paradox story for this dataset
vcd::assocstats(margin.table(UCBAdmissions, c(1, 2)))
# Cramer's V and Cohen's w coincide when every factor in a term is binary,
# and diverge once a term involves a factor with more levels
hec <- loglm(~ (Hair + Eye + Sex)^2, data = HairEyeColor)
assoc_strength(hec) # Hair, Eye each have 4 levels
Run the code above in your browser using DataLab