## One-sample test.
## Hollander & Wolfe (1973), 29f.
## Hamilton depression scale factor measurements in 9 patients with
## mixed anxiety and depression, taken at the first (x) and second
## (y) visit after initiation of a therapy (administration of a
## tranquilizer).
x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)
wilcox.exact(x, y, paired = TRUE, alternative = "greater")
wilcox.exact(y - x, alternative = "less") # The same.
stopifnot(wilcox.test(y-x)$p.value == wilcox.exact(y -x)$p.value)
## Two-sample test.
## Hollander & Wolfe (1973), 69f.
## Permeability constants of the human chorioamnion (a placental
## membrane) at term (x) and between 12 to 26 weeks gestational
## age (y). The alternative of interest is greater permeability
## of the human chorioamnion for the term pregnancy.
x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46)
y <- c(1.15, 0.88, 0.90, 0.74, 1.21)
wilcox.exact(x, y, alternative = "g") # greater
x <- rnorm(10)
y <- rnorm(10, 2)
wilcox.exact(x, y, conf.int = TRUE)
<testonly>if (!any(duplicated(c(x,y)))) {
we <- wilcox.exact(x, y, conf.int = TRUE)
wt <- wilcox.test(x, y, conf.int = TRUE)
we$parameter <- NULL
we$method <- NULL
wt$parameter <- NULL
wt$method <- NULL
stopifnot(all.equal(wt, we))
}</testonly>
# Data from the StatXact-4 manual, page 221, diastolic blood pressure
treat <- c(94, 108, 110, 90)
contr <- c(80, 94, 85, 90, 90, 90, 108, 94, 78, 105, 88)
# StatXact 4 for Windows: p.value = 0.0989, point prob = 0.019
wilcox.exact(contr, treat, conf.int=T)
<testonly>we <- wilcox.exact(contr, treat, conf.int=T)
stopifnot(we$estimate > we$conf.int[1] & we$estimate < we$conf.int[2])</testonly>
# StatXact 4 for Windows: p.value = 0.0542, point prob = 0.019
wilcox.exact(contr, treat, alternative="less", conf.int=T)
# paired observations
# Data from the StatXact-4 manual, page 167, serum antigen level
# StatXact 4 for Windows: p.value=0.0021 (page 168)
pre <- c(149, 0, 0, 259, 106, 255, 0, 52, 340, 65, 180, 0, 84, 89, 212, 554,
500, 424, 112, 2600)
post <- c(0, 51, 0, 385, 0, 235, 0, 0, 48, 65, 77, 0, 0, 0, 53, 150, 0, 165,
98, 0)
wilcox.exact(pre, post, paired=T, conf.int=T)
<testonly>we <- wilcox.exact(pre, post, paired=T, conf.int=T)
stopifnot(we$estimate > we$conf.int[1] & we$estimate < we$conf.int[2])</testonly>
<testonly>stopifnot(wilcox.exact(1:8)$p.value == 0.0078125)
stopifnot(wilcox.exact(c(1:7,7))$p.value == 0.0078125)
stopifnot(wilcox.exact(c(1,1,1))$p.value == 0.25)
x <- rnorm(10)
y <- rnorm(10)
stopifnot(wilcox.test(x,y,conf.int=T)$estimate ==
wilcox.exact(x,y,conf.int=T)$estimate)
stopifnot(wilcox.test(x,conf.int=T)$estimate ==
wilcox.exact(x,conf.int=T)$estimate)</testonly>
Run the code above in your browser using DataLab