Learn R Programming

exactRankTests (version 0.7-5)

perm.test: One and Two Sample Permutation Test

Description

Performs the permutation test for the one and two sample problem.

Usage

## S3 method for class 'default':
perm.test(x, y, paired=FALSE, alternative=c("two.sided", "less", "greater"),
                            mu=0, exact=NULL, conf.int=FALSE, 
                            conf.level=0.95, tol=NULL, ...)
## S3 method for class 'formula':
perm.test(formula, data, subset, na.action, \dots)

Arguments

x
numeric vector of integer data values.
y
numeric vector of integer data values with length greater length x (otherwise pperm(y,x,...) is computed and a warning given).
paired
a logical indicating whether you want a paired test.
alternative
the alternative hypothesis must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.
mu
a number specifying an optional location parameter.
exact
a logical indicating whether an exact p-value should be computed.
conf.int
a logical indicating whether a confidence interval should be computed.
conf.level
confidence level of the interval.
tol
real. real valued scores are mapped into integers by multiplication. Make sure that the absolute difference between the "true" quantile and the approximated quantile is less than tol. This might not be p
formula
a formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs a factor with two levels giving the corresponding groups.
data
an optional data frame containing the variables in the model formula.
subset
an optional vector specifying a subset of observations to be used.
na.action
a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").
...
further arguments to be passed to or from methods.

Value

  • A list with class "htest" containing the following components:
  • statisticthe value of the test statistic with a name describing it.
  • p.valuethe p-value for the test.
  • pointprobthis gives the probability of observing the test statistic itself (called point-prob).
  • null.valuethe location parameter mu.
  • alternativea character string describing the alternative hypothesis.
  • methodthe type of test applied.
  • data.namea character string giving the names of the data.
  • conf.inta confidence interval for the location parameter. (Only present if argument conf.int = TRUE.)

Details

The permutation test is performed for integer valued observations or scores. If real values x or y are passed to this function the following applies: if exact is true (i.e. the sample size is less than 50 observations) and tol is not given, the scores are mapped into ${1,\dots,N}$, see pperm for the details. Otherwise the p-values are computed using tol. If the sample size exceeds $50$ observations, the usual normal approximation is used.

P-values are computed according to the StatXact-manual, see pperm.

For (in principle) continuous variables the confidence sets represent the "largest shift in location being consistent with the observations". For discrete variables with only a few categories they are hard to interpret. In the case of binary data (e.g. success / failure) the confidence sets can be interpreted as the differences of two success-rates covered by the data. For a detailed description see R"ohmel (1996).

Confidence intervals are only available for independent samples.

References

Joachim R"ohmel (1996). Precision intervals for estimates of the difference in success rates for binary random variables based on the Permutation Principle. Biometrical Journal, 38(8), 977--993.

Cyrus R. Mehta and Nitin R. Patel (1998). StatXact-4 for Windows. Manual, Cytel Software Cooperation, Cambridge, USA

Examples

Run this code
# 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