简体   繁体   中英

Python and Statsmodels: How to include the alternative test_t hypothesis?

Consider the following example:

 df = pd.read_csv('myFile.txt',delim_whitespace=True,header=None) df.columns=['vary','vax1','varx2'] y,X = ps.dmatrices('vary ~ varx1 + varx2',data=df, return_type='dataframe') model = sm.OLS(y,X) # Describe Model results = model.fit() # Fit model print results.summary() hypotheses = 'varx1 = 0.0' t_test = results.t_test(hypotheses) print(t_test) 

This is testing "H0: The coefficient of varX1 is zero" against the alternative hypothesis "H1: The coefficient of varX1 is different from zero"

I would like to make "H1: The coefficient of VarX1 is less than -c, c>0" (the one-sided alternative).

Is it possible?

Statsmodels doesn't seem to allow one-tailed tests. You can instead invoke scipy.stats after fitting your model:

from scipy import stats
c = 0.5 #lower bound
print(stats.t.cdf(var_x1, df, loc=c, scale=1))

which will give you the area under the t-dist to the right of c.

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