跟兩獨(dú)立樣本相對(duì)應(yīng)的是兩配對(duì)樣本,生物醫(yī)學(xué)中常見(jiàn)的案例是治療前后的比較,兩種檢測(cè)方法的比較(同一樣本接受不同的檢驗(yàn)方法)、配對(duì)的對(duì)象接受不同的處理。根據(jù)不同適用條件,常用的統(tǒng)計(jì)方法有:兩配對(duì)樣本的t檢驗(yàn)、兩配對(duì)樣本的非參數(shù)檢驗(yàn)(如Wilcoxon符號(hào)秩檢驗(yàn))、配對(duì)卡方檢驗(yàn)(McNemar)。 其本質(zhì)是兩配對(duì)樣本的差值與0的比較。跟兩獨(dú)立樣本的t檢驗(yàn)一樣,兩配對(duì)樣本的t檢驗(yàn)用到的函數(shù)也是t.test {stats}。t.test {stats}默認(rèn)的是兩獨(dú)立樣本的t檢驗(yàn),在進(jìn)行兩配對(duì)樣本的t檢驗(yàn)時(shí),只需要將默認(rèn)的paired = FALSE修改為paired = TRUE即可。 t.test {stats}:Student's t-Test,Performs one and two sample t-tests on vectors of data.
李斌,賀佳等.醫(yī)學(xué)統(tǒng)計(jì)學(xué)(第6版).北京:人民衛(wèi)生出版社,2013. ①數(shù)據(jù)導(dǎo)入 library(openxlsx) pttest<-read.xlsx("D:/Temp/pddata.xlsx",1) d=pttest$before-pttest$after shapiro.test(d) t.test(pttest$before,pttest$after,paired = TRUE) 或 t.test(pttest[1:12,2],pttest[1:12,3],paired =TRUE) 當(dāng)配對(duì)樣本的差值不滿足正態(tài)分布時(shí),需要改用非參數(shù)檢驗(yàn)。差值正態(tài)的數(shù)據(jù)也可以使用非參,只是檢驗(yàn)效率低一點(diǎn)而已。跟兩獨(dú)立樣本的非參數(shù)檢驗(yàn)一樣,兩相關(guān)樣本的非參數(shù)檢驗(yàn)常用的函數(shù)也是wilcox.test {stats}.,但需要將默認(rèn)的paired = FALSE修改為paired = TRUE。 wilcox.test {stats}:Wilcoxon Rank Sum and Signed Rank Tests,Performs one- and two-sample Wilcoxon tests on vectors of data; the latter is also known as ‘Mann-Whitney’ test.
顏虹等.醫(yī)學(xué)統(tǒng)計(jì)學(xué)(第2版).北京:人民衛(wèi)生出版社,2010.8. ①數(shù)據(jù)導(dǎo)入 library(openxlsx) nptest<-read.xlsx("D:/Temp/pddata.xlsx",2) d=nptest$before-nptest$after shapiro.test(d) wilcox.test(nptest$before,nptest$after,paired = TRUE) 或 wilcox.test(nptest[1:12,2],nptest[1:12,3],paired =TRUE) 配對(duì)卡方檢驗(yàn)我們用的McNemar's Chi-squared Test,使用函數(shù)mcnemar.test {stats}:Performs McNemar's chi-squared test for symmetry of rows and columns in a two-dimensional contingency table.
x:either a two-dimensional contingency table in matrix form, or a factor object. y:a factor object; ignored if x is a matrix. correct:a logical indicating whether to apply continuity correction when computing the test statistic. 顏虹等.醫(yī)學(xué)統(tǒng)計(jì)學(xué)(第2版).北京:人民衛(wèi)生出版社,2010.8. ①數(shù)據(jù)導(dǎo)入 library(openxlsx) mctest<-read.xlsx("D:/Temp/pddata.xlsx",3) pd<-matrix(c(mctest$頻數(shù)),nrow = 2,dimnames = list("甲法" = c("陽(yáng)性", "陰性"),"乙法" = c("陽(yáng)性", "陰性"))) mcnemar.test(pd) END |
|
來(lái)自: Memo_Cleon > 《待分類》