R 中多项式的拟合值:参考类别的系数?

2023-11-21

我使用 nnet 包中的函数 multinom 来运行多项逻辑回归。

In multinomial logistic regression, as I understand it, the coefficients are the changes in the log of the ratio of the probability of a response over the probability of the reference response (i.e., ln(P(i)/P(r))=B1+B2*X... where i is one response category, r is the reference category, and X is some predictor).

但是,fitting(multinom(...)) 会生成每个类别的估计值,甚至是参考类别r.

EDIT例子:

set.seed(1)
library(nnet)
DF <- data.frame(X = as.numeric(rnorm(30)), 
                 Y = factor(sample(letters[1:5],30, replace=TRUE)))
DF$Y<-relevel(DF$Y, ref="a") #ensure a is the reference category
model <- multinom(Y ~ X, data = DF)
coef(model)
#  (Intercept)           X
#b   0.1756835  0.55915795
#c  -0.2513414 -0.31274745
#d   0.1389806 -0.12257963
#e  -0.4034968  0.06814379

head(fitted(model))
#          a         b          c         d         e
#1 0.2125982 0.2110692 0.18316042 0.2542913 0.1388810
#2 0.2101165 0.1041655 0.26694618 0.2926508 0.1261210
#3 0.2129182 0.2066711 0.18576567 0.2559369 0.1387081
#4 0.1733332 0.4431170 0.08798363 0.1685015 0.1270647
#5 0.2126573 0.2102819 0.18362323 0.2545859 0.1388516
#6 0.1935449 0.3475526 0.11970164 0.2032974 0.1359035

head(DF)
#           X Y
#1 -0.3271010 a

计算响应之间的预测概率比b和回应a对于第 1 行,我们计算exp(0.1756835+0.55915795*(-0.3271010))=0.9928084。我发现这对应于第 1 行的拟合 P(b)/P(a) (0.2110692/0.2125982=0.9928084)。

参考类别的拟合概率是通过代数计算得出的(例如,0.2110692/exp(0.1756835+0.55915795*(-0.3271010)))?

有没有办法获得参考类别的预测概率的方程?


我也有同样的问题,看了一圈后我认为解决方案是: 给定 3 个类:a、b、c 以及算法输出的拟合(模型)概率 pa、pb、pc,您可以从这 3 个方程重建这些概率:

log(pb/pa) = beta1*X

log(pc/pa) = beta2*X

pa+pb+pc=1

其中 beta1、beta2 是 coef(model) 输出的行,X 是您的输入数据。

使用这些方程你可以得到:

pb = exp(beta1*X)/(1+exp(beta1*X)+exp(beta2*X))

pc = exp(beta2*X)/(1+exp(beta1*X)+exp(beta2*X))

pa = 1 - pb - pc
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

R 中多项式的拟合值:参考类别的系数? 的相关文章

随机推荐