R 程式設計/多項式模型
外觀
< R 程式設計
- mlogit 包。
- mnlogit 包
- Bayesm 包
- multinom() nnet
- multinomial(), 用於vglm() VGAM
- clogit()在 survival 包中
- mclogit 包。
我們考慮一個 多項式有序邏輯 模型,其中閾值未知。首先,我們模擬假資料。我們在邏輯分佈中抽取殘差。然後我們抽取一些解釋變數 x,並將潛在變數 ys 定義為 x 的線性函式。請注意,我們將常數設定為 0,因為在這個模型中,常數和閾值無法同時識別。因此,我們需要固定其中一個引數。然後,我們定義閾值 (-1,0,1),並使用 cut() 函式定義觀察變數 y。所以 y 是一個有序的多項式變數。
N <- 10000
u <- rlogis(N)
x <- rnorm(N)
ys <- x + u
mu <- c(-Inf,-1,0,1, Inf)
y <- cut(ys, mu)
plot(y,ys)
df <- data.frame(y,x)
可以使用 MASS 包中的 polr() 函式透過最大似然估計該模型。由於無法識別常數和閾值,R 預設假設常數等於 0。
library(MASS)
fit <- polr(y ~ x, method = "logistic", data = df)
summary(fit)
- bayespolr()(arm) 執行多項式有序邏輯的貝葉斯估計
library("arm")
fit <- bayespolr(y ~ x, method = "logistic", data = df)
summary(fit)
我們透過在正態分佈中抽取誤差項並在 4 個類別中截斷潛在變數來生成假資料。
N <- 1000
u <- rnorm(N)
x <- rnorm(N)
ys <- x + u
mu <- c(-Inf,-1,0,1, Inf)
y <- cut(ys, mu)
plot(y,ys)
df <- data.frame(x,y)
可以使用最大似然方法擬合模型。可以使用 MASS 包中的 polr() 函式以及 probit 方法來完成此操作。
library(MASS)
fit <- polr(y ~ x, method = "probit", data = df)
summary(fit)
- bayespolr()(arm) 執行多項式有序機率的貝葉斯估計
該模型由 Beggs、Cardell 和 Hausman 於 1981 年在計量經濟學中提出。[2][3] 一個應用是 Combes 等人的論文,解釋了候選人成為教授的排名。[3] 在生物醫學文獻中也被稱為 Plackett–Luce 模型,或在營銷中被稱為 爆炸邏輯模型。[3]
- 可以使用由 Gary King 及其合著者開發的 anchors 包估計條件有序分層機率。[4]
- ↑ Harry Joe、Laing Wei Chou 和 Hongbin Zhang (2006)。mprobit:二元/序數響應的多元機率模型。R 包版本 0.9-2。
- ↑ Beggs, S; Cardell, S; Hausman, J (1981). "Assessing the potential demand for electric cars". Journal of Econometrics. 17: 1–19. doi:10.1016/0304-4076(81)90056-7.
- ↑ a b c Combes, Pierre-Philippe; Linnemer, Laurent; Visser, Michael (2008). "Publish or peer-rich? The role of skills and networks in hiring economics professors". Labour Economics. 15 (3): 423–41. doi:10.1016/j.labeco.2007.04.003.
- ↑ Jonathan Wand、Gary King、Olivia Lau (2009)。anchors:用於錨定小插圖資料的軟體。統計軟體雜誌,即將出版。網址 http://www.jstatsoft.org/。
