*disclaimer
843425
順序ロジスティック回帰
ランダム効果なし
MASSパッケージの中の polr()関数
- 目的変数が factor型になっている必要がある
- as.factor() を使って変換しておく
result <- polr(y ~ a + b + c, データ, method="logistic") summary(result)
- 説明変数間を * でつなぐと可能な交互作用の組み合わせを試してくれる
- 変数が多いとエラーになる
- step() を使って、ステップワイズで、モデルの選択
step(result)
- p値を出すには、texregパッケージの screenreg()
screenreg(result)
ordinalパッケージの clm()関数
result <- clm(y ~ a + b + c, data=データ) summary(result)
- p値を出力してくれる
- このあとstepで試す
step(result)
- たくさん出てくるので、
result.step <- step(result) summary(result.step)
rmsパッケージの中の orm()関数やlrm()関数
errdat5.ordered.OLR.orm <- orm(Criterion ~ ., errdat5.ordered)
errdat5.ordered.OLR.lrm <- lrm(Criterion ~ ., errdat5.ordered)
ランダム効果あり
ordinalパッケージの clmm()関数
result <- clmm(y ~ a + b + c + (1|d) + (1|e), data=データ) summary(result)
- p値を出力してくれる
- 参考
- https://rdrr.io/cran/ordinal/man/clmm.html
- ランダム傾きの指定は、clmm2()
- clmm2の方が古い、clmmへ移行中
多項ロジスティック回帰:目的変数は三つ以上だが、順序がない
- nnet::multinom()
その他
- mlogit::mlogit()
結果の可視化
install.packages("effects") library(effects) plot(allEffects(モデル式))
- 変数ごとに個別に表示させるオプション selection=数字
> plot(allEffects(natural.essay.logi), selection=1) > plot(allEffects(natural.essay.logi), selection=2) > plot(allEffects(natural.essay.logi), selection=3) > plot(allEffects(natural.essay.logi), selection=4) > plot(allEffects(natural.essay.logi), selection=5) > plot(allEffects(natural.essay.logi), selection=6)
- 個別に変数名を指定してもよい。
plot(effect("cohesion",natural.essay.logi))
https://sugiura-ken.org/wiki/