Example R programs and commands
9. R commands for multiple-comparison tests
# All lines preceded by the "#" character are my comments.
# All other left-justified lines are my input.
# All other indented lines are the R program output.
#
# Tabulated data for input to R
#
# ORIGINAL FORMAT
# Skateboarding injuries (per 1000 board-hours.)
# NOTE: not the same data as in example 8.
#
# Mar Jun Sep
# 9.7 4.2 9.6
# 9.8 6.7 9.4
# 9.6 5.8 8.9
# 9.5 7.5 9.4
# 4.4 9.5
#
#
mar <- c(9.7,9.8,9.6,9.5,NA) # only 4 values
jun <- c(4.2,6.7,5.8,7.5,4.4)
sep <- c(9.6,9.4,8.9,9.4,9.5)
month <- gl(3,5,labels=c("Mar","Jun","Sep"))
injuries <- c(mar,jun,sep)
# Pairwise t-test:
pairwise.t.test(injuries,month)
Pairwise comparisons using t tests with pooled SD
data: injuries and month
Mar Jun
Jun 0.00011 -
Sep 0.63313 0.00011
P value adjustment method: holm
# Tukey multiple-comparison test:
TukeyHSD(aov(injuries~month))
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = injuries ~ month)
$month
diff lwr upr p adj
Jun-Mar -3.93 -5.525460 -2.334540 0.0000978
Sep-Mar -0.29 -1.885460 1.305460 0.8770268
Sep-Jun 3.64 2.135786 5.144214 0.0001146
# Similar computation with the sample means reordered:
TukeyHSD(aov(injuries~month), ordered=TRUE)
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = injuries ~ month)
$month
diff lwr upr p adj
Sep-Jun 3.64 2.135786 5.144214 0.0001146
Mar-Jun 3.93 2.334540 5.525460 0.0000978
Mar-Sep 0.29 -1.305460 1.885460 0.8770268
# Nonparametric multiple comparison
pairwise.wilcox.test(injuries,month)
Pairwise comparisons using Wilcoxon rank sum test
data: injuries and month
Mar Jun
Jun 0.036 -
Sep 0.063 0.036
P value adjustment method: holm
Warning messages:
1: cannot compute exact p-value with ties in: wilcox.test.default(xi, xj, ...)
2: cannot compute exact p-value with ties in: wilcox.test.default(xi, xj, ...)