熊猫:用小组d实施布雷斯奇帕根

2021-02-25 21:45:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用以下代码来评估小组成员:

Y = df['billsum']

X = df[['years_exp', 'leg_totalbills', 'amtsum', 'amtsumlag.1', 'cfcontrol', 'sen',\
        'Republican']]

X = add_constant(X)

from pandas.stats.plm import PanelOLS
reg=PanelOLS(Y,X,time_effects=True)

print('MODEL 1: OLS Regression Results',reg)

MODEL 1: OLS Regression Results 
-------------------------Summary of Regression Analysis-------------------------

Formula: Y ~ <const> + <years_exp> + <leg_totalbills> + <amtsum> + <amtsumlag.1>
             + <cfcontrol> + <sen> + <Republican>

Number of Observations:         6930
Number of Degrees of Freedom:   17

R-squared:         0.7081
Adj R-squared:     0.7074

Rmse:              0.2423

F-stat (8, 6913):  1048.1396, p-value:     0.0000

Degrees of Freedom: model 16, resid 6913

-----------------------Summary of Estimated Coefficients------------------------
      Variable       Coef    Std Err     t-stat    p-value    CI 2.5%   CI 97.5%
--------------------------------------------------------------------------------
         const     0.0000        nan        nan        nan        nan        nan
     years_exp     0.0205     0.0005      43.71     0.0000     0.0196     0.0214
leg_totalbills     0.0148     0.0005      32.94     0.0000     0.0139     0.0157
        amtsum    -0.0003     0.0001      -3.17     0.0015    -0.0005    -0.0001
   amtsumlag.1     0.0005     0.0001       5.03     0.0000     0.0003     0.0007
--------------------------------------------------------------------------------
     cfcontrol     0.3629     0.0168      21.61     0.0000     0.3299     0.3958
           sen     0.0598     0.0177       3.38     0.0007     0.0251     0.0944
    Republican     0.6540     0.0114      57.38     0.0000     0.6317     0.6764
---------------------------------End of Summary---------------------------------

我想做一个异教徒的异方差检验:

^{pr2}$

我知道我应该输入残差(可能是数组格式)和exog_het,在我的例子中是X。问题是我不知道如何让PanelOLS输出残差。实际上,我不确定残差是否是PanelOLS输出中报告的Std Err。所以,问题是:残差在regression output中显示在哪里,我如何让Pandas独立地输出它,以便将其输入到Breusch-Pagan测试中。在