我正在使用python 3.6在一个数据集上运行一些统计测试。我试图完成的是在数据集和趋势线之间运行t检验,以确定统计显著性。我使用scipy来做这件事,但是我不确定我应该在测试中包括哪些变量来获得我需要的结果。
到目前为止,我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
p = np.load('data.npy')
#0=1901
start=0
end=100
plt.figure()
plt.plot(a,annualmean, '-')
slope, intercept, r_value, p_value, std_err = stats.linregress(a,annualmean)
plt.plot(a,intercept+slope*a, 'r')
annualmean=[]
for n in range(start,end):
annualmean.append(np.nanmean(p[n]))
#Trendline Plots
a=range(start,end)
year1 = 1901
print(stats.ttest_ind(annualmean,a))现在代码正在工作,没有错误消息,但是我得到了一个令人难以置信的小p值,我不认为它是正确的。如果有人知道我应该在t-test中写入哪些变量,这将非常有帮助。谢谢!
发布于 2017-07-08 02:06:21
因此,我对如何检验统计显著性感到困惑。我已经为行中的数据计算出了一个p值:
slope, intercept, r_value, p_value, std_err = stats.linregress(a,annualmean)我需要做的就是:打印(P_value)
发布于 2017-06-24 00:42:36
我没有资格发表评论,但根据您的代码,您正在对年度平均数据和0-100之间的数组之间的平均值进行t测试。scipy.stats.ttest接受两个大小相等的数组,您要比较它们的平均值。
根据documentation的说法
scipy.stats.ttest_ind(a, b, axis=0, equal_var=True)[source]
Parameters:
a, b : array_like
The arrays must have the same shape, except in the dimension corresponding to axis (the first, by default).另外,在趋势线和原始数据之间进行t检验是没有意义的,但这是another forum的一个问题
https://stackoverflow.com/questions/44725992
复制相似问题