简体   繁体   中英

Test null hypothesis that regression coefficient equals a nonzero value in statsmodels OLS

In Python statsmodels, calling summary() on an OLS model gives the p value for coefficients equaling zero. Is there a way to test that the coefficient equals some nonzero value?

This CrossValidated question shows that offset() can be used for this in R.

You can use a trick repametrizing y~x into y - T*x ~ x where T is the tested value.

If you want to be more formal you can take the coefficient and its standard error and compute

and then the df for the t are the same as they would be for a test with for.
Moreover you can get the p-value from the t-value using the function pt() .

statsmodels includes several methods for hypothesis tests in the results classes. Those are mostly based on Wald test and make it very easy to test linear hypothesis on the parameters.

see for example t_test https://www.statsmodels.org/stable/generated/statsmodels.regression.linear_model.OLSResults.t_test.html

A simple expample is results.t_test("x1 = 1") when there is a variable with name "x1".

https://github.com/statsmodels/statsmodels/issues/3676 is a FAQ issue that provides some overview of existing and planned hypothesis tests after a model has been estimated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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