获取 statsmodel RollingOLS 结果摘要信息

lea*_*key 5 python statistics regression linear-regression statsmodels

我正在 statsmodels.api 上使用 RollingOLS 函数运行滚动回归,并想知道是否有可能获取滚动回归中完成的每个回归的汇总统计数据(beta、r^2 等)。

使用单个 OLS 回归,您可以获得这样的摘要信息,

X_opt  = X[:, [0,1,2,3]]
regressor_OLS = sm.OLS(endog= y, exog= X_opt).fit()
regressor_OLS.summary()


                          OLS Regression Results                            
==============================================================================
Dep. Variable:                      y   R-squared:                       0.951
Model:                            OLS   Adj. R-squared:                  0.948
Method:                 Least Squares   F-statistic:                     296.0
Date:                Wed, 08 Aug 2018   Prob (F-statistic):           4.53e-30
Time:                        00:46:48   Log-Likelihood:                -525.39
No. Observations:                  50   AIC:                             1059.
Df Residuals:                      46   BIC:                             1066.
Df Model:                           3                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const       5.012e+04   6572.353      7.626      0.000    3.69e+04    6.34e+04
x1             0.8057      0.045     17.846      0.000       0.715       0.897
x2            -0.0268      0.051     -0.526      0.602      -0.130       0.076
x3             0.0272      0.016      1.655      0.105      -0.006       0.060
==============================================================================
Omnibus:                       14.838   Durbin-Watson:                   1.282
Prob(Omnibus):                  0.001   Jarque-Bera (JB):               21.442
Skew:                          -0.949   Prob(JB):                     2.21e-05
Kurtosis:                       5.586   Cond. No.                     1.40e+06
==============================================================================
Run Code Online (Sandbox Code Playgroud)

有没有办法获取每个窗口上运行的回归的信息以进行滚动回归?

小智 0

我们无法为每个滑动窗口生成一个表。但是,我们可以使用内置函数来访问参数、tvalues、pvalues 等。

rols = RollingOLS(y, x, window)
rres = rols.fit()
rres.params  # gives table of coefficients for each window
rres.tvalues # gives table of t-values for each window
rres.pvalues # gives table of p-values for each window
Run Code Online (Sandbox Code Playgroud)

有关我们可以使用的更多函数,请参阅https://www.statsmodels.org/dev/
generated/statsmodels.regression.rolling.RollingRegressionResults.html#statsmodels.regression.rolling.RollingRegressionResults。