当我使用 python statsmodels 在 OLS 中添加外生变量时,为什么 R-Squared 会减少 [英] Why would R-Squared decrease when I add an exogenous variable in OLS using python statsmodels

查看:38
本文介绍了当我使用 python statsmodels 在 OLS 中添加外生变量时,为什么 R-Squared 会减少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正确理解了 OLS 模型,那应该永远不会是这种情况?

If I understand the OLS model correctly, this should never be the case?

trades['const']=1
Y = trades['ret']+trades['comms']
#X = trades[['potential', 'pVal', 'startVal', 'const']]
X = trades[['potential', 'pVal', 'startVal']]

from statsmodels.regression.linear_model import OLS
ols=OLS(Y, X)
res=ols.fit()
res.summary()

如果我打开 const,我得到 0.22 的 rsquared,关闭它,我得到 0.43.这怎么可能?

If I turn the const on, I get a rsquared of 0.22 and with it off, I get 0.43. How is that even possible?

推荐答案

在此处查看答案 Statsmodels:计算拟合值和 R 平方

Rsquared 遵循不同的定义,具体取决于模型中是否存在常量.

Rsquared follows a different definition depending on whether there is a constant in the model or not.

带有常数的线性模型中的 Rsquared 是标准定义,它使用与仅均值模型的比较作为参考.总平方和被贬低.

Rsquared in a linear model with a constant is the standard definition that uses a comparison with a mean only model as reference. Total sum of squares is demeaned.

没有常数的线性模型中的 Rsquared 与完全没有回归量的模型进行比较,或者常数的影响为零.在这种情况下,R 平方计算使用不贬值的总平方和.

Rsquared in a linear model without a constant compares with a model that has no regressors at all, or the effect of the constant is zero. In this case the R squared calculation uses a total sum of squares that does not demean.

因为如果我们添加或删除一个常数,定义就会发生变化,所以 R 平方可以采用任何一种方式.如果我们添加额外的解释变量,实际解释的平方和总是会增加,如果新变量没有贡献,则保持不变,

Since the definition changes if we add or drop a constant, the R squared can go either way. The actual explained sum of squares will always increase if we add additional explanatory variables, or stay unchanged if the new variable doesn't contribute anything,

这篇关于当我使用 python statsmodels 在 OLS 中添加外生变量时,为什么 R-Squared 会减少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆