Skip to content

Instantly share code, notes, and snippets.

@nozma

nozma/Sec8ans.R

Created Jul 30, 2016
Embed
What would you like to do?
カテゴリカルデータ解析第8章練習問題解答
# 練習問題
# 1.
JointSports
result <- loglm(Freq ~ opinion * year * grade * gender, data = JointSports)
step(result)
step(result, k = log(sum(JointSports$Freq)))
mosaicplot(xtabs(Freq ~ year + grade + gender + opinion, data = JointSports))
# 2.
# (a)
tabledata <- xtabs(Freq ~ sex + method2 + age.group, data = Suicide)
tabledata
# (b)
model.base <- loglm(~ sex + method2 + age.group, data = tabledata)
model.sm <- update(model.base, . ~ . + sex:method2)
model.sa <- update(model.base, . ~ . + sex:age.group)
model.ma <- update(model.base, . ~ . + method2:age.group)
# AIC
extractAIC(model.sm)
extractAIC(model.sa)
extractAIC(model.ma)
# BIC
extractAIC(model.sm, k = log(sum(tabledata)))
extractAIC(model.sa, k = log(sum(tabledata)))
extractAIC(model.ma, k = log(sum(tabledata)))
# (c)
model.full <- loglm(~ sex * method2 * age.group, data = tabledata)
step(model.full)
step(model.full, k = log(sum(tabledata)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.