繁体   English   中英

从 Python 中的 OLS 摘要中获取 Durbin-Watson 和 Jarque-Bera 统计数据

[英]Get Durbin-Watson and Jarque-Bera statistics from OLS Summary in Python

我正在为一列值运行 OLS 摘要。 OLS 的一部分是 Durbin-Watson 和 Jarque-Bera (JB) 统计数据,我想直接提取这些值,因为它们已经计算完毕,而不是像我现在使用 durbinwatson 那样将这些步骤作为额外步骤运行。

这是我的代码:

import pandas as pd
import statsmodels.api as sm

csv = mydata.csv
df = pd.read_csv(csv)
var = df[variable]
year = df['Year']
model = sm.OLS(var,year)
results = model.fit()
summary = results.summary()
print summary
#print dir(results)
residuals = results.resid
durbinwatson = statsmodels.stats.stattools.durbin_watson(residuals, axis=0)
print durbinwatson

结果:

                           OLS Regression Results                            
==============================================================================
Dep. Variable:                    LST   R-squared:                       1.000
Model:                            OLS   Adj. R-squared:                  1.000
Method:                 Least Squares   F-statistic:                 3.026e+05
Date:                Fri, 10 Nov 2017   Prob (F-statistic):           2.07e-63
Time:                        20:37:03   Log-Likelihood:                -82.016
No. Observations:                  32   AIC:                             166.0
Df Residuals:                      31   BIC:                             167.5
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Year           0.1551      0.000    550.069      0.000       0.155       0.156
==============================================================================
Omnibus:                        1.268   Durbin-Watson:                   1.839
Prob(Omnibus):                  0.530   Jarque-Bera (JB):                1.087
Skew:                          -0.253   Prob(JB):                        0.581
Kurtosis:                       2.252   Cond. No.                         1.00
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

我发现通过打印

dir(results)

我可以获得 OLS 摘要元素的列表,并且我可以像我在这里所做的那样毫无问题地提取测试的残差(或 R 平方和东西)但我不能只提取 durbin watson 或 Jarque贝拉。 我试过这个:

print results.wald_test

但我只是得到错误:

<bound method OLSResults.wald_test of <statsmodels.regression.linear_model.OLSResults object at 0x0D05B3F0>>

而且我什至在摘要的目录中找不到jarque bera test。 有什么帮助吗?

import pandas as pd
import statsmodels.api as sm
from statsmodels.stats.stattools import durbin_watson #add this import 


csv = mydata.csv
df = pd.read_csv(csv)
var = df[variable]
year = df['Year']
model = sm.OLS(var,year)
results = model.fit()
summary = results.summary()
dw = float(durbin_watson(results.resid)) # this line will access the durbin watson score 
print(dw)

暂无
暂无

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

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