Python statsmodel 中的 GLM 残差

GLM Residual in Python statsmodel

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

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

res.resid()

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

res$resid

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

resid_anscombe Anscombe 残差。

resid_anscombe_scaled 缩放 Anscombe 残差。

resid_anscombe_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 方法返回的结果实例的属性。