我想要一个系数和Newey-West标准误差。
我正在寻找Python库(理想情况下,任何工作解决方案都可以),它可以完成以下R代码所做的工作:
library(sandwich)
library(lmtest)
a <- matrix(c(1,3,5,7,4,5,6,4,7,8,9))
b <- matrix(c(3,5,6,2,4,6,7,8,7,8,9))
temp.lm = lm(a ~ b)
temp.summ <- summary(temp.lm)
temp.summ$coefficients <- unclass(coeftest(temp.lm, vcov. = NeweyWest))
print (temp.summ$coefficients)
结果:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.0576208 2.5230532 0.8155281 0.4358205
b 0.5594796 0.4071834 1.3740235 0.2026817
我得到了系数,并把它们与标准误差联系起来。
我看到了statsmodels.stats.sandwich_covariance.cov_hac模块,但是我不知道如何使用OLS。
已编辑(2015年10月31日),以反映2015年秋季时
statsmodels
的首选编码样式。在
statsmodels
版本0.6.1中,您可以执行以下操作:或者在拟合模型之后可以使用
get_robustcov_results
方法:statsmodels
的默认值与R
中等效方法的默认值略有不同。通过将vcov,
调用更改为以下内容,可以使R
方法等效于statsmodels
默认值(我在上面所做的操作):你也可以在《熊猫》(0.17)中扮演纽伊·韦斯特(Newey West),尽管我相信这个计划是为了反对《熊猫》中的OLS:
相关问题 更多 >
编程相关推荐