順序ロジット/プロビット
順序ロジスティック回帰(順序ロジット)の練習。この資料にSPSSとStataによる順序ロジットの例が載っている。ここにStata形式のデータがあるのでこれを使わせてもらう。
library(foreign) # Stata形式のデータを読むためにforeignパッケージを読み込み。 library(MASS) # 順序ロジットの関数polrを含むMASSパッケージを読み込む。 library(car) # 分散分析表を算出するAnova関数を含むcarパッケージを読み込む。 shuttle2 <- read.dta("shuttle2.dta") names(shuttle2) # 目的変数を順序尺度の因子に変換。 shuttle2$distress2 <- ordered(shuttle2$distress,levels=c("None","1 or 2","3 plus")) # 順序ロジットの実行。偏回帰係数と定数項の値はSPSSとStataと同じ。 # 標準誤差とt値がSPSSと異なるが、これはStataも違う値になっている。 # 変数選択にはstepAICが使える。 (shu.olr <- polr(distress2~date+temp, data=shuttle2, method="logistic", Hess=T)) Anova(shu.olr) # 分散分析表 # モデルが全体として有意であるか、切片だけのモデルと尤度比検定。 (shu.olr0 <- polr(distress2~1, data=shuttle2, method="logistic", Hess=T)) anova(shu.olr,shu.olr0) # 順序プロビットだとこう。AICで言えばロジットよりプロビットの方が当てはまりが良さそう。 (shu.opr <- polr(distress2~date+temp, data=shuttle2, method="probit", Hess=T)) Anova(shu.opr) # 二つのモデルの比較。違いがあるとはいえない。 anova(shu.olr, shu.opr)