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)?
答案 0 :(得分:0)
来自SciPy.org文件: https://docs.scipy.org/doc/scipy-.14.0/reference/generated/scipy.stats.linregress.html
in:print" r-squared:",r_value ** 2
out:r-squared:0.15286643777
对于其他参数,请尝试:
print ('Intercept is: ', (intercept))
print ('Slope is: ', (slope))
print ('R-Value is: ', (r_value))
print ('Std Error is: ', (std_err))
print ('p-value is: ', (p_value))