简体   繁体   English

R如何获得多项logit的置信区间?

[英]R How to get confidence interval for multinominal logit?

Let me use UCLA example on multinominal logit as a running example--- 让我用多项式logit上的UCLA示例作为运行示例---

library(nnet)
library(foreign)

ml <- read.dta("http://www.ats.ucla.edu/stat/data/hsbdemo.dta")
ml$prog2 <- relevel(ml$prog, ref = "academic")
test <- multinom(prog2 ~ ses + write, data = ml)

dses <- data.frame(ses = c("low", "middle", "high"), write = mean(ml$write))
predict(test, newdata = dses, "probs")

I wonder how can I get 95% confidence interval? 我想知道如何获得95%的置信区间?

Simply use the confint function on your model object. 只需在模型对象上使用confint函数即可。

ci <- confint(test, level=0.95)

Note that confint is a generic function and a specific version is run for multinom , as you can see by running 请注意, confint是一个通用函数,并且为multinom运行特定版本,正如您可以通过运行看到的那样

> methods(confint)
[1] confint.default   confint.glm*      confint.lm*       confint.multinom*
[5] confint.nls* 

EDIT: 编辑:

as for the matter of calculating confidence interval for the predicted probabilities, I quote from: https://stat.ethz.ch/pipermail/r-help/2004-April/048917.html 至于计算预测概率的置信区间的问题,我引用自: https//stat.ethz.ch/pipermail/r-help/2004-April/048917.html

Is there any possibility to estimate confidence intervalls for the probabilties with the multinom function? 是否有可能通过多项功能估计概率的置信度?

No, as confidence intervals (sic) apply to single parameters not probabilities (sic). 不,因为置信区间(sic)适用于单个参数而非概率(原文如此)。 The prediction is a probability distribution, so the uncertainty would have to be some region in Kd space, not an interval. 预测是概率分布,因此不确定性必须是Kd空间中的某个区域,而不是区间。 Why do you want uncertainty statements about predictions (often called tolerance intervals/regions)? 为什么你想要关于预测的不确定性陈述(通常称为公差间隔/区域)? In this case you have an event which happens or not and the meaningful uncertainty is the probability distribution. 在这种情况下,您有一个事件发生与否,有意义的不确定性是概率分布。 If you really have need of a confidence region, you could simulate from the uncertainty in the fitted parameters, predict and summarize somehow the resulting empirical distribution. 如果您确实需要置信区域,则可以根据拟合参数的不确定性进行模拟,以某种方式预测和总结所得到的经验分布。

This can be accomplished with the effects package, which I showcased for another question at Cross Validated here . 这可以通过effects包实现,我在此处展示了另一个问题。

Let's look at your example. 让我们看看你的例子。

library(nnet)
library(foreign)

ml <- read.dta("http://www.ats.ucla.edu/stat/data/hsbdemo.dta")
ml$prog2 <- relevel(ml$prog, ref = "academic")
test <- multinom(prog2 ~ ses + write, data = ml)

Instead of using the predict() from base , we use Effect() from effects 除了使用的predict()base ,我们使用Effect()effects

require(effects)

fit.eff <- Effect("ses", test, given.values = c("write" = mean(ml$write)))

data.frame(fit.eff$prob, fit.eff$lower.prob, fit.eff$upper.prob)

  prob.academic prob.general prob.vocation L.prob.academic L.prob.general L.prob.vocation U.prob.academic
1     0.4396845    0.3581917     0.2021238       0.2967292     0.23102295      0.10891758       0.5933996
2     0.4777488    0.2283353     0.2939159       0.3721163     0.15192359      0.20553211       0.5854098
3     0.7009007    0.1784939     0.1206054       0.5576661     0.09543391      0.05495437       0.8132831
  U.prob.general U.prob.vocation
1      0.5090244       0.3442749
2      0.3283014       0.4011175
3      0.3091388       0.2444031

If we want to, we can also plot the predicted probabilities with their respective confidence intervals using the facilities in effects . 如果我们想要,我们还可以使用effects的设施绘制预测概率及其各自的置信区间。

plot(fit.eff)

Imgur

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM