![](/img/trans.png)
[英]Statistics Tests (Kolmogorov and T-test) with Python and Rpy2
[英]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采用兩個大小相等的數組,您要比較它們的均值。
根據文檔 :
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檢驗是沒有意義的,但這是另一個論壇的問題
原來,我對如何檢驗統計顯着性感到困惑。 我已經找到了該行中數據的p值:
slope, intercept, r_value, p_value, std_err = stats.linregress(a,annualmean)
我要做的就是:print(p_value)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.