I'm performing pairwise Wilcoxon test with a simple data set and get surprising results. Comparing group A and C using the full set (A, B and C) returns a p-value different than comparing A and C with a data subset (A and C groups only).
dfx <- data.frame(group = c(rep('A', 8), rep('B', 15), rep('C', 6)), sex = sample(c("M", "F"), size = 29, replace = TRUE), age = runif(n = 29, min = 18, max = 54))
pairwise.wilcox.test(dfx$age, dfx$group, pool.sd=F, paired=F)
Pairwise comparisons using Wilcoxon rank sum test
data: dfx$age and dfx$group
A B
B 0.55 -
C 0.13 0.19
P value adjustment method: holm
dfx.ac<-dfx[which(dfx$group!='B'),]
pairwise.wilcox.test(dfx.ac$age, dfx.ac$group, pool.sd=F, paired=F)
Pairwise comparisons using Wilcoxon rank sum test
data: dfx.ac$age and dfx.ab$group
A
C 0.043
P value adjustment method: holm
Using Wilcoxon test on individual data returns the same p-value.
a<-dfx[which(dfx$group=='A'),]$age
c<-dfx[which(dfx$group=='C'),]$age
wilcox.test(a,c)
W = 8, p-value = 0.04262
wilcox.test(dfx.ac$age~dfx.ac$group)
W = 8, p-value = 0.04262
What do I do wrong with pairwise.wilcox.test(dfx$age, dfx$group, pool.sd=F, paired=F) ?
Same difference if I compare a set of 3 groups or 4 groups. dfx <- data.frame( group = c(rep('A', 8), rep('B', 15), rep('C', 6), rep('D', 9)), sex = sample(c("M", "F"), size = 38, replace = TRUE), age = runif(n = 38, min = 18, max = 54))
dfx.nb<-dfx[which(dfx$group!='B'),]
pairwise.wilcox.test(dfx$age,dfx$group, pool.sd=F, paired=F)
A B C
B 1.00 - -
C 0.57 0.62 -
D 0.56 0.56 1.00
pairwise.wilcox.test(dfx.nb$age,dfx.nb$group, pool.sd=F, paired=F)
A C
C 0.28 -
D 0.28 0.95