Python statsmodel 中的 GLM 残差

问题描述

如何在 Python 中为所有 303 个观测值生成残差:

from statsmodels.stats.outliers_influence import OLSInfluence
OLSInfluence(resid)

res.resid()

我正在尝试生成类似于我们在 R 中生成的残差:

res$resid

解决方法

statsmodels 没有 resid 的默认 GLM,但它有以下内容

resid_anscombe Anscombe 残差。

resid_anscombe_scaled 缩放 Anscombe 残差。

resid_anscombe_unscaled Unscaled Anscombe 残差。

resid_deviance 偏差残差。

resid_pearson Pearson 残差。

resid_response 响应残差。

resid_working 工作残差。

https://www.statsmodels.org/stable/generated/statsmodels.genmod.generalized_linear_model.GLMResults.html

残差 y - E(y|x) 是响应残差 resid_response

这些残差可用作 fit 方法返回的结果实例的属性。