![](/img/trans.png)
[英]Robustness issue of statsmodel Linear regression (ols) - Python
[英]Linear Regression (OLS): Confidence Intervals are not being calculated accurately using Statsmodel summary_Frame()
不正确的置信区间
我想从 python 中的 OLS model 计算我的预测值的置信区间。 我在 statmodel 中找到了一个 function,它可以帮助您创建每个预测值的 dataframe,使用 get_prediction() 和 summary_frame() 的预测值、CI 的上限和下限。
不幸的是,我的上下 CI 与结果不匹配。 请找到我的代码和结果截图的附加截图。
第 1 行,例如: Forecasted Value - 11.788462, SE - 0.580693, for 95% CI
Lower Bound should be = 11.788462 - (1.96 * 0.580693) = 10.65030372
Upper Bound should be = 11.788462 + (1.96 * 0.580693) = 12.92662028
但是屏幕截图中的结果与这些数字不匹配。 我不确定我是否做错了什么。 任何帮助表示赞赏。
statsmodels 默认使用 t 分布在 OLS 等线性回归模型中进行推理。
由于样本量非常小和自由度低,t 分布的临界值与正态分布的临界值在可观察到的量级上有所不同。
下面将 1.96 的临界值替换为 df=5 的 t 分布的临界值。 这些值与问题中附加的屏幕截图中的 statsmodels 结果相匹配。
from scipy import stats
11.788462 + stats.t.ppf(0.025, 5) * 0.580693
Out[12]: 10.295743121550677
11.788462 + stats.t.isf(0.025, 5) * 0.580693
Out[13]: 13.281180878449325
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.