用MATLAB做T檢驗(ttest)

t-檢驗:


t-檢驗,又稱student‘s t-test,可以用於比較兩組數據是否來自同一分佈(可以用於比較兩組數據的區分度),假設了數據的正態性,並反應兩組數據的方差在統計上是否有顯著差異。

matlab中提供了兩種相同形式的方法來解決這一假設檢驗問題,分別爲ttest方法和ttest2方法,兩者的參數、返回值類型均相同,不同之處在於ttest方法做的是 One-sample and paired-sample t-test,而ttest2則是 Two-sample t-test with pooled or unpooled variance estimate, performs an unpaired two-sample t-test。但是這裏至於paired和unpaired之間的區別我卻還沒搞清楚,只是在Student's t-test中看到了如下這樣一段解釋:

“Two-sample t-tests for a difference in mean involve independent samples, paired samples and overlapping samples. Pairedt-tests are a form ofblocking, and have greater power than unpaired tests when the paired units are similar with respect to "noise factors" that are independent of membership in the two groups being compared.[8] In a different context, paired t-tests can be used to reduce the effects ofconfounding factors in anobservational study.”

因此粗略認爲paired是考慮了噪聲因素的。

在同樣的兩組數據上分別用ttest和ttest2方法得出的結果進行比較,發現ttest返回的參數p普遍更小,且置信區間ci也更小。


最常用用法:
[H,P,CI]=ttest2(x,y);(用法上ttest和ttest2相同,完整形式爲[H,P,CI, STATS]=ttest2(x,y, ALPHA);)

其中,x,y均爲行向量(維度必須相同),各表示一組數據,ALPHA爲可選參數,表示設置一個值作爲t檢驗執行的顯著性水平(performs the test at the significance level
    (100*ALPHA)%),在不設置ALPHA的情況下默認ALPHA爲0.05,即計算x和y在5%的顯著性水平下是否來自同一分佈(假設是否被接受)
結果:H=0,則表明零假設在5%的置信度下被拒絕(根據當設置x=y時候,返回的H=0推斷而來),即x,y在統計上可看做來自同一分佈的數據;H=1,表明零假設被拒絕,即x,y在統計上認爲是來自不同分佈的數據,即有區分度。

P爲一個概率,matlab help中的解釋是“ the p-value, i.e., the probability of observing the given result, or one more extreme, by chance if the null  hypothesis is true.  Small values of P cast doubt on the validity of  the null hypothesis.” 暫且認爲表示判斷值在真實分佈中被觀察到的概率(?不太懂)

CI爲置信區間(confidence interval),表示“a 100*(1-ALPHA)% confidence interval for the true difference of population means”,即達到100*(1-ALPHA)%的置信度的數據區間(?)


應用:常與k-fold crossValidation(交叉驗證)聯用可以用於兩種算法效果的比較,例如A1,A2兩算法得出的結果分別爲x,y,且從均值上看mean(x)>mean(y),則對[h,p,ci]=ttest2(x,y);當h=1時,表明可以從統計上斷定算法A1的結果大於(?)A2的結果(即兩組數據均值的比較是有意義的),h=0則表示不能根據平均值來斷定兩組數據的大小關係(因爲區分度小)

 

臨時學的,沒經過太多測試,不一定對,還請高手指教。



另外還有在某個ppt(http://jura.wi.mit.edu/bio/education/hot_topics/pdf/matlab.pdf)中看到這樣一頁


參考資料:

經驗+自身理解

matlab 7.11.0(R2010b)的幫助文檔

wikipedia

http://www.biosino.org/pages/newhtm/r/schtml/One_002d-and-two_002dsample-tests.html


轉載請註明出處,請尊重他人勞動成果

發佈了12 篇原創文章 · 獲贊 13 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章