# Example from Gardner & Altman (1989), p. 30
# two treatments A and B, 1 means improvement, 0 means no improvement
# confidence sets cf. R\"ohmel (1996)
A <- c(rep(1, 61), rep(0, 19))
B <- c(rep(1, 45), rep(0, 35))
pt <- perm.test(A, B, conf.int=TRUE, exact=TRUE)
pt
<testonly>stopifnot(round(pt$conf.int, 4) == c(0.0526, 0.3429))</testonly>
# the blood pressure example from StatXact-manual, page 262:
treat <- c(94, 108, 110, 90)
contr <- c(80, 94, 85, 90, 90, 90, 108, 94, 78, 105, 88)
pt <- perm.test(treat, contr)
pt
<testonly>stopifnot(round(pt$p.value, 4) == 0.1040)</testonly>
pt <- perm.test(treat, contr, alternative="greater")
pt
<testonly>stopifnot(round(pt$p.value, 4) == 0.0564)</testonly>
pt <- perm.test(treat, contr, exact=FALSE)
pt
<testonly>stopifnot(round(pt$p.value, 4) == 0.1070)</testonly>
# one-sample AIDS data (differences only), page 179
diff <- c(-149, 51, 0, 126, -106, -20, 0, -52, -292, 0, -103, 0, -84, -89,
-159, -404, -500, -259, -14, -2600)
# p-values in StatXact == 0.0011 one-sided, 0.0021 two.sided
perm.test(diff)
perm.test(diff, alternative="less")
pt <- perm.test(diff, exact=FALSE)
<testonly># StatXact page 179
stopifnot(round(pt$p.value, 4) == 0.0878)</testonly>
Run the code above in your browser using DataLab