gpt4 book ai didi

python - 如何在 Statsmodels 中获得稳健回归 (RLM) 的 R 平方?

转载 作者:太空狗 更新时间:2023-10-30 00:19:25 26 4
gpt4 key购买 nike

在衡量拟合优度时,R 平方似乎是“简单”线性模型的一种普遍理解(和接受)的衡量方法。但如果是 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
==============================================================================

最佳答案

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

关于python - 如何在 Statsmodels 中获得稳健回归 (RLM) 的 R 平方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31655196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com