快捷搜索: 王者荣耀 脱发

R语言和医学统计学:非参数检验的补充

医学和生信笔记,专注R语言在临床医学中的使用,R语言数据分析和可视化。

探索发现

前段时间有小伙伴问到,在进行 Friedman M 检验后,如何进行两两比较,也就是多重检验的问题。数据是第四版孙振球医学统计学中的P126页,多个相关样本两两比较的q检验。

当时我天真的以为这个q检验就是 SNK q检验,但是发现SNK q检验是针对多个样本均数的两两比较,并不适用于非参数检验后多重比较。

The Newman–Keuls or Student–Newman–Keuls (SNK) method is a stepwise multiple comparisons procedure used to identify sample means that are significantly different from each other. It was named after Student (1927), D. Newman, and M. Keuls.–维基百科

经过一番探索后才发现原来课本上说的这个q检验,应该是 quade test。

果然还是基础不牢,地动山摇啊!当时上课时这部分不是重点,也没有好好看过,现在现实来给我上了一课!

解决问题

接下来就是使用R语言实现quade test。但是自带的quade.test()函数不能进行两两比较,还是要借助第三方包。

# 准备数据,课本例8-9的数据
df <- matrix(
  c(8.4, 11.6, 9.4, 9.8, 8.3, 8.6, 8.9, 7.8,
    9.6, 12.7, 9.1, 8.7, 8, 9.8, 9, 8.2,
    9.8, 11.8, 10.4, 9.9, 8.6, 9.6, 10.6, 8.5,
    11.7, 12, 9.8, 12, 8.6, 10.6, 11.4, 10.8
    ),
  byrow = F, nrow = 8,
  dimnames = list(1:8,LETTERS[1:4])
  )

print(df)
##      A    B    C    D
## 1  8.4  9.6  9.8 11.7
## 2 11.6 12.7 11.8 12.0
## 3  9.4  9.1 10.4  9.8
## 4  9.8  8.7  9.9 12.0
## 5  8.3  8.0  8.6  8.6
## 6  8.6  9.8  9.6 10.6
## 7  8.9  9.0 10.6 11.4
## 8  7.8  8.2  8.5 10.8

先进行 Friedman M检验:

friedman.test(df)
## 
## 	Friedman rank sum test
## 
## data:  df
## Friedman chi-squared = 15.152, df = 3, p-value = 0.001691

接下来进行 quade 检验:

library(PMCMRplus) # 加载R包

quadeAllPairsTest(df,dist = "Normal")
## 
## 	Pairwise comparisons using Quades test	with standard-normal approximation
## data: df
##   A       B       C     
## B 0.2200  -       -     
## C 0.0017  0.0644  -     
## D 1.7e-07 7.7e-05 0.0860
## 
## P value adjustment method: holm

当然也可以有更加详细的结果:

res <- quadeAllPairsTest(df,dist = "Normal")
res[,1:4]

group1 group2 statistic      p.value
1      B      A  1.226488 2.200150e-01
2      C      A  3.526154 1.686568e-03
3      C      B  2.299666 6.440153e-02
4      D      A  5.549859 1.715396e-07
5      D      B  4.323371 7.683144e-05
6      D      C  2.023706 8.600089e-02

这个结果和课本上也不是完全一样,不过不影响结果。还有很多其他的方法可以选择,除了这个quade检验,还可以用Nemenyi等检验方法。

医学和生信笔记,专注R语言在临床医学中的使用,R语言数据分析和可视化。
经验分享 程序员 微信小程序 职场和发展