python實現T檢驗
t檢驗,亦稱student t檢驗(Student’s t test),主要用於樣本含量較小(例如n < 30),總體標準差σ未知的正態分佈。
t檢驗是用t分佈理論來推論差異發生的概率,從而比較兩個平均數的差異是否顯著
其假設如下:
H0:μ = μ0 (零假設null hypothesis)
H1:μ ≠ μ0(備擇假設alternative hypothesis)
python代碼實現如下:
from scipy import stats
stats.ttest_ind(data1,data2)
如果數據中有nan,則T檢驗結果也爲nan,此時需要去除nan值,再進行T檢驗