首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python:统计T-test

Python:统计T-test
EN

Stack Overflow用户
提问于 2017-06-24 00:18:37
回答 2查看 996关注 0票数 0

我正在使用python 3.6在一个数据集上运行一些统计测试。我试图完成的是在数据集和趋势线之间运行t检验,以确定统计显著性。我使用scipy来做这件事,但是我不确定我应该在测试中包括哪些变量来获得我需要的结果。

到目前为止,我的代码如下:

代码语言:javascript
复制
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中写入哪些变量,这将非常有帮助。谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-08 02:06:21

因此,我对如何检验统计显著性感到困惑。我已经为行中的数据计算出了一个p值:

代码语言:javascript
复制
slope, intercept, r_value, p_value, std_err = stats.linregress(a,annualmean)

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

票数 0
EN

Stack Overflow用户

发布于 2017-06-24 00:42:36

我没有资格发表评论,但根据您的代码,您正在对年度平均数据和0-100之间的数组之间的平均值进行t测试。scipy.stats.ttest接受两个大小相等的数组,您要比较它们的平均值。

根据documentation的说法

代码语言:javascript
复制
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的一个问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44725992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档