【发布时间】:2015-04-29 11:34:28
【问题描述】:
scipy.stats.linregress 返回与斜率对应的 p 值,但没有截距的 p 值。考虑文档中的以下示例:
>>> from scipy import stats
>>> import numpy as np
>>> x = np.random.random(10)
>>> y = np.random.random(10)
>>> slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
>>> p_value
0.40795314163864016
根据文档,p-value 是“假设检验的双边 p 值,其零假设是斜率为零。”我想获得相同的统计数据,但是对于截距而不是斜率。
statsmodels.regression.linear_model.OLS 立即返回两个系数的 p 值:
>>> import numpy as np
>>> import statsmodels.api as sm
>>> X = sm.add_constant(x)
>>> model = sm.OLS(y,X)
>>> results = model.fit()
>>> results.pvalues
array([ 0.00297559, 0.40795314])
仅使用 scipy,如何获得截距的 p 值 (0.40795314163864016)?
【问题讨论】:
标签: python statistics scipy statsmodels