检查 Python 统计模型中回归中的两个系数是否不同

Check whether two coefficients in a regression differ in Python statsmodels

在 R 中,car::linearHypothesis 函数可用于检验两个系数相等的假设(它们的差与零显着不同)。这是来自 documentation:

的示例

linearHypothesis(mod.duncan, "income = education")

根据 this CrossValidated answer 这在 MATLAB 中也可用 linhyptest

是否有 Python statsmodels 回归模型的等价物?

大多数模型的结果类有几种Wald检验方法。

t_test 为单一假设向量化。
wald_test 用于联合假设。
wald_test_terms 自动测试 "terms",即系数的子集联合为零,类似于基于 Wald 测试的类型 3 方差分析 table。

例如参见 OLS 之后 t_test 的文档字符串,但所有模型都继承相同的方法并以相同的方式工作 (*)。 https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLSResults.t_test.html

例如

>>> t_test = results.t_test("income = education")
>>> print(t_test)

(*) 有一些模型不遵循标准模式,这些 wald 测试尚不可用。

t_test 使用正态分布或 t 分布,其他两个 wald 检验使用卡方分布或 F 分布。可以使用 model.fit.
中的 use_t 关键字来选择分布 如果 use_t=True 则使用 t 和 F 分布。如果是 False,则使用正态分布和卡方分布。线性回归模型的默认值为 t 和 F,所有其他模型的默认值为 normal 和 chisquare。