如何在Statsmodels中获得鲁棒回归(RLM)的R平方?

问题描述 投票:5回答:1

在测量拟合优度时,R-Squared似乎是“简单”线性模型的常用理解(并被接受)度量。但是在statsmodels(以及其他统计软件)的情况下,RLM不包括R平方和回归结果。有没有办法让它“手动”计算,或许与Stata中的方式类似?

或者是否有另一种措施可以从sm.RLS产生的结果中使用/计算出来?

这就是Statsmodels正在制作的:

import numpy as np
import statsmodels.api as sm

# Sample Data with outliers
nsample = 50
x = np.linspace(0, 20, nsample)
x = sm.add_constant(x)
sig = 0.3
beta = [5, 0.5]
y_true = np.dot(x, beta)
y = y_true + sig * 1. * np.random.normal(size=nsample)
y[[39,41,43,45,48]] -= 5   # add some outliers (10% of nsample)

# Regression with Robust Linear Model
res = sm.RLM(y, x).fit()
print(res.summary())

哪个输出:

                    Robust linear Model Regression Results                    
==============================================================================
Dep. Variable:                      y   No. Observations:                   50
Model:                            RLM   Df Residuals:                       48
Method:                          IRLS   Df Model:                            1
Norm:                          HuberT                                         
Scale Est.:                       mad                                         
Cov Type:                          H1                                         
Date:                 Mo, 27 Jul 2015                                         
Time:                        10:00:00                                         
No. Iterations:                    17                                         
==============================================================================
                 coef    std err          z      P>|z|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
const          5.0254      0.091     55.017      0.000         4.846     5.204
x1             0.4845      0.008     61.555      0.000         0.469     0.500
==============================================================================
python regression linear-regression statsmodels
1个回答
0
投票

由于OLS返回R2,我建议使用简单的线性回归将实际值与拟合值相对应。无论拟合值来自何处,这种方法都会为您提供相应R2的指示。

© www.soinside.com 2019 - 2024. All rights reserved.