Performs one-sample and two-sample permutation tests on vectors of data.
perm.test(x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0,
paired = FALSE, all.perms = TRUE, num.sim = 20000, plot = FALSE, stat = mean, ...)
A (non-empty) numeric vector of data values.
An optional numeric vector data values.
A character string specifying the alternative hypothesis, and
must be one of "two.sided"
(default), "greater"
or "less"
.
Only the initial letter needs to be specified.
A number indicating the null value of the location parameter (or the difference in location parameters if performing a two-sample test).
Logical, indicating whether or not a two-sample test should be paired, and is ignored for a one-sample test.
Logical. The exact p-value is attempted when all.perms
(i.e., all permutations)
is TRUE
(default), and is simulated when all.perms
is FALSE
or when
computing an exact p-value requires more than num.sim
calculations.
The upper limit on the number of permutations generated.
Logical. If TRUE
, then plot the histogram of the permutation distribution;
otherwise, list the p-value.
Function, naming the test statistic, such as mean
and median
.
Optional arguments to stat
;
and is the second argument to stat
when unspecified.
For example, if stat
equals mean
, then the second argument
trim
denotes the fraction (0 to 0.5) of observations to be trimmed
from each end of x
and y
before the mean is computed.
Same as the input.
Same as the input.
The p-value of the permutation test.
A paired test using data x
and nonNULL y
is
equivalent to a one-sample test using data x-y
.
The output states more details about the permutation test, such as one-sample or two-sample,
and whether or not the p.value
calculated was based on all permutations.
Higgins, J. J. (2004) Introduction to Modern Nonparametric Statistics.
# NOT RUN {
# One-sample test
print( x <- rnorm(10,0.5) )
perm.test( x, stat=median )
# Two-sample unpaired test
print( y <- rnorm(13,1) )
perm.test( x, y )
# }
Run the code above in your browser using DataLab