简体   繁体   English

Python statsmodels logit wald测试输入

[英]Python statsmodels logit wald test input

I have fitted a logisitic regression model to some data, everything is working great. 我已经为某些数据拟合了逻辑回归模型,一切都很好。 I need to calculate the wald statistic which is a function of the model result. 我需要计算wald统计量,该统计量是模型结果的函数。

My problem is that I do not understand, from the documentation, what the wald test requires as input? 我的问题是,我从文档中不了解瓦尔德测试需要什么作为输入? Specifically what is the R matrix and how is it generated? 具体来说,R矩阵是什么,如何生成?

I tried simply inputting the data I used to train and test the model as the R matrix, but I do not think this is correct. 我尝试仅输入用于训练和测试模型的数据作为R矩阵,但是我认为这是不正确的。 The documentation suggest examining the examples however none give an example of this test. 文档建议检查示例,但没有给出此测试的示例。 I also asked the same question on crossvalidated but got shot down. 我在交叉验证中也问过同样的问题,但遭到拒绝。

Kind regards 亲切的问候

http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.discrete.discrete_model.LogitResults.wald_test.html#statsmodels.discrete.discrete_model.LogitResults.wald_test http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.discrete.discrete_model.LogitResults.wald_test.html#statsmodels.discrete.discrete_model.LogitResults.wald_test

The Wald test is used to test if a predictor is significant or not, of the form: Wald检验用于检验以下形式的预测变量是否有效:

W = (beta_hat - beta_0) / SE(beta_hat) ~ N(0,1) W =(beta_hat-beta_0)/ SE(beta_hat)〜N(0,1)

So somehow you'll want to input the predictors into the test. 因此,您需要以某种方式将预测变量输入到测试中。 Judging from the example of the t.test and f.test , it may be simpler to input a string or tuple to indicate what you are testing. t.testf.test的示例来看,输入字符串或元组来指示要测试的内容可能更简单。

Here is their example using a string for the f.test : 这是使用f.test字符串的示例

from statsmodels.datasets import longley
from statsmodels.formula.api import ols
dta = longley.load_pandas().data
formula = 'TOTEMP ~ GNPDEFL + GNP + UNEMP + ARMED + POP + YEAR'
results = ols(formula, dta).fit()
hypotheses = '(GNPDEFL = GNP), (UNEMP = 2), (YEAR/1829 = 1)'
f_test = results.f_test(hypotheses)
print(f_test)

And here is their example using a tuple: 这是他们使用元组的示例

import numpy as np
import statsmodels.api as sm
data = sm.datasets.longley.load()
data.exog = sm.add_constant(data.exog)
results = sm.OLS(data.endog, data.exog).fit()
r = np.zeros_like(results.params)
r[5:] = [1,-1]
T_test = results.t_test(r)

If you're still struggling getting the wald test to work, include your code and I can try to help make it work. 如果您仍在努力使wald测试正常工作,请包括您的代码,我可以尝试帮助使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM