perm.test: One and Two Sample Permutation Test

View source: R/perm.test.R

perm.testR Documentation

One and Two Sample Permutation Test


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


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



numeric vector of integer data values.


numeric vector of integer data values.


a logical indicating whether you want a paired test.


the alternative hypothesis must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.


a number specifying an optional location parameter.


a logical indicating whether an exact p-value should be computed.

a logical indicating whether a confidence interval should be computed.


confidence level of the interval.


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 possible due to memory/time limitations. See pperm.


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.


an optional data frame containing the variables in the model formula.


an optional vector specifying a subset of observations to be used.


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.


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,…,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. When the sample sizes are unbalanced, length(x) needs to be smaller than length(y).


A list with class "htest" containing the following components:


the value of the test statistic with a name describing it.


the p-value for the test.


this gives the probability of observing the test statistic itself.


the location parameter mu.


a character string describing the alternative hypothesis.


the type of test applied.

a character string giving the names of the data.

a confidence interval for the location parameter. (Only present if argument = TRUE.)


Confidence intervals may need some cpu-time ...


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 & Nitin R. Patel (2001), StatXact-5 for Windows. Manual, Cytel Software Cooperation, Cambridge, USA


# 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))
perm.test(A, B,, exact=TRUE)

# one-sample AIDS data (differences only), Methta and Patel (2001),
# Table 8.1 page 181

ppdiff <- pre - post

# p-values in StatXact == 0.0011 one-sided, 0.0021 two.sided, page 183

perm.test(ppdiff, alternative="less")
perm.test(ppdiff, exact=FALSE)

exactRankTests documentation built on April 26, 2022, 9:06 a.m.