Statistics for Laboratory Scientists ( 140.615 )

Permutation and Non-Parametric Tests

Example 1 from class

The paired data.

x <- c(117.3, 100.1,  94.5, 135.5,  92.9, 118.9, 144.8, 103.9, 103.8, 153.6, 163.1)
y <- c(145.9,  94.8, 108.0, 122.6, 130.2, 143.9, 149.9, 138.5,  91.7, 162.6, 202.5)
d <- y-x
d
##  [1]  28.6  -5.3  13.5 -12.9  37.3  25.0   5.1  34.6 -12.1   9.0  39.4

The Wilcoxon signed rank test.

wilcox.test(d)
## 
##  Wilcoxon signed rank exact test
## 
## data:  d
## V = 55, p-value = 0.05371
## alternative hypothesis: true location is not equal to 0

The t-test.

t.test(y,x,paired=TRUE)
## 
##  Paired t-test
## 
## data:  y and x
## t = 2.5015, df = 10, p-value = 0.03137
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##   1.611238 27.879671
## sample estimates:
## mean difference 
##        14.74545
t.test(d)
## 
##  One Sample t-test
## 
## data:  d
## t = 2.5015, df = 10, p-value = 0.03137
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##   1.611238 27.879671
## sample estimates:
## mean of x 
##  14.74545

Example 2 from class

The two-sample data.

x <- c(43.3, 57.1, 35.0, 50.0, 38.2, 61.2)
y <- c(51.9, 95.1, 90.0, 49.7, 101.5, 74.1, 84.5, 46.8, 75.1)

The Wilcoxon rank-sum test.

wilcox.test(x,y)
## 
##  Wilcoxon rank sum exact test
## 
## data:  x and y
## W = 8, p-value = 0.02557
## alternative hypothesis: true location shift is not equal to 0

The t-test.

t.test(x,y)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -3.3217, df = 12.416, p-value = 0.005835
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -44.368724  -9.297942
## sample estimates:
## mean of x mean of y 
##  47.46667  74.30000

Example 3

xA <- c(27.0,54.6,33.5,27.6,46.0,22.2,44.2,17.3,15.9,32.8)
xB <- c(17.4,20.5,13.9,14.8,27.9,10.6,33.7,15.4,25.0,24.1)

stripchart(list(xA,xB),vertical=T,pch=21,xlim=c(0.5,2.5))
segments(0.9,mean(xA),1.1,mean(xA),lwd=2,col="red")
segments(1.9,mean(xB),2.1,mean(xB),lwd=2,col="blue")
abline(h=mean(c(xA,xB)),lty=2)

t.test(xA,xB)
## 
##  Welch Two Sample t-test
## 
## data:  xA and xB
## t = 2.5336, df = 14.224, p-value = 0.02364
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   1.822368 21.737632
## sample estimates:
## mean of x mean of y 
##     32.11     20.33
wilcox.test(xA,xB)
## 
##  Wilcoxon rank sum exact test
## 
## data:  xA and xB
## W = 78, p-value = 0.03546
## alternative hypothesis: true location shift is not equal to 0

Let’s see how one outlier influences the test statistics!

sort(xA)
##  [1] 15.9 17.3 22.2 27.0 27.6 32.8 33.5 44.2 46.0 54.6
sort(xA,decreasing=TRUE)
##  [1] 54.6 46.0 44.2 33.5 32.8 27.6 27.0 22.2 17.3 15.9
order(xA)
##  [1]  9  8  6  1  4 10  3  7  5  2
order(xA,decreasing=TRUE)
##  [1]  2  5  7  3 10  4  1  6  8  9
xAnew <- xA
xAnew[2] <- 99.9
xA
##  [1] 27.0 54.6 33.5 27.6 46.0 22.2 44.2 17.3 15.9 32.8
xAnew
##  [1] 27.0 99.9 33.5 27.6 46.0 22.2 44.2 17.3 15.9 32.8
stripchart(list(xAnew,xB),vertical=T,pch=21,xlim=c(0.5,2.5))
segments(0.9,mean(xAnew),1.1,mean(xAnew),lwd=2,col="red")
segments(1.9,mean(xB),2.1,mean(xB),lwd=2,col="blue")
abline(h=mean(c(xAnew,xB)),lty=2)

t.test(xA,xB)$p.value
## [1] 0.02364417
t.test(xAnew,xB)$p.value # why is the p-value now > 0.05?
## [1] 0.06869718
wilcox.test(xA,xB)$p.value
## [1] 0.03546299
wilcox.test(xAnew,xB)$p.value # why are the p-values the same?
## [1] 0.03546299