Python:统计T检验

Python: Statistics T-test

我正在使用 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 检验,那将非常有帮助。 谢谢!

我没有资格发表评论,但根据您的代码,您正在进行 t 检验,比较年度平均数据和 0-100 数组之间的均值。 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

的问题

原来我对如何检验统计显着性感到困惑。我已经计算出行中数据的 p 值:

slope, intercept, r_value, p_value, std_err = stats.linregress(a,annualmean)

我需要做的就是: 打印(p_value)