[英]Test null hypothesis that regression coefficient equals a nonzero value in statsmodels OLS
[英]Python and Statsmodels: How to include the alternative test_t hypothesis?
考虑以下示例:
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)
这是针对替代假设“ H1:varX1的系数不同于零”测试“ H0:varX1的系数为零”
我想使“ H1:VarX1的系数小于-c,c> 0”(单侧替代)。
可能吗?
Statsmodels似乎不允许单尾测试。 您可以在拟合模型后调用scipy.stats :
from scipy import stats
c = 0.5 #lower bound
print(stats.t.cdf(var_x1, df, loc=c, scale=1))
这将为您提供c右边的t-dist下的区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.