perm.test: Permutation Test

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/perm.test.R

Description

Performs one-sample and two-sample permutation tests on vectors of data.

Usage

1
2
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, ...)

Arguments

x

A (non-empty) numeric vector of data values.

y

An optional numeric vector data values.

alternative

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.

mu

A number indicating the null value of the location parameter (or the difference in location parameters if performing a two-sample test).

paired

Logical, indicating whether or not a two-sample test should be paired, and is ignored for a one-sample test.

all.perms

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.

num.sim

The upper limit on the number of permutations generated.

plot

Logical. If TRUE, then plot the histogram of the permutation distribution; otherwise, list the p-value.

stat

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.

Details

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.

Value

alternative

Same as the input.

mu

Same as the input.

p.value

The p-value of the permutation test.

Note

The formulas computed within perm.test are based on the textbook by Higgins (2004).

Author(s)

Steven T. Garren, James Madison University, Harrisonburg, Virginia, USA

References

Higgins, J. J. (2004) Introduction to Modern Nonparametric Statistics.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 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 )

Example output

 [1]  1.6013242  1.5846410 -0.5714917  0.3988142  0.5416978  1.3851507
 [7] -0.2418826  1.3553764  0.5802484 -0.4113348
[[1]]
[1] "One-sample permutation test was performed."

[[2]]
[1] "p-value was calculated based on all permutations."

$alternative
[1] "two.sided"

$mu
[1] 0

$p.value
[1] 0.078125

 [1]  1.5735208  1.5312516  0.4463142  1.2528721 -0.5620620  2.3429980
 [7]  0.7756172  1.6497653  0.7889176  0.5107436  0.7542697  1.4606170
[13]  0.4759810
[[1]]
[1] "Unpaired two-sample permutation test was performed."

[[2]]
[1] "p-value was estimated based on 20000 simulations."

$alternative
[1] "two.sided"

$mu
[1] 0

$p.value
[1] 0.2584

jmuOutlier documentation built on Aug. 6, 2019, 1:03 a.m.