跟两独立样本相对应的是两配对样本,生物医学中常见的案例是治疗前后的比较,两种检测方法的比较(同一样本接受不同的检验方法)、配对的对象接受不同的处理。根据不同适用条件,常用的统计方法有:两配对样本的t检验、两配对样本的非参数检验(如Wilcoxon符号秩检验)、配对卡方检验(McNemar)。 其本质是两配对样本的差值与0的比较。跟两独立样本的t检验一样,两配对样本的t检验用到的函数也是t.test {stats}。t.test {stats}默认的是两独立样本的t检验,在进行两配对样本的t检验时,只需要将默认的paired = FALSE修改为paired = TRUE即可。 t.test {stats}:Student's t-Test,Performs one and two sample t-tests on vectors of data.
李斌,贺佳等.医学统计学(第6版).北京:人民卫生出版社,2013. ①数据导入 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) 当配对样本的差值不满足正态分布时,需要改用非参数检验。差值正态的数据也可以使用非参,只是检验效率低一点而已。跟两独立样本的非参数检验一样,两相关样本的非参数检验常用的函数也是wilcox.test {stats}.,但需要将默认的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.
颜虹等.医学统计学(第2版).北京:人民卫生出版社,2010.8. ①数据导入 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) 配对卡方检验我们用的McNemar's Chi-squared Test,使用函数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. 颜虹等.医学统计学(第2版).北京:人民卫生出版社,2010.8. ①数据导入 library(openxlsx) mctest<-read.xlsx("D:/Temp/pddata.xlsx",3) pd<-matrix(c(mctest$频数),nrow = 2,dimnames = list("甲法" = c("阳性", "阴性"),"乙法" = c("阳性", "阴性"))) mcnemar.test(pd) END |
|
来自: Memo_Cleon > 《待分类》