Random Permutation Test

Description

Performs a random permutation test on the relationship between two discrete variables, or by using a function.

Details

These functions are related to "Permuting Super Bowl Theory" which can be found in the working papers section of http://www.burns-stat.com. The paper explains statistical permutation tests via a discussion of the Super Bowl indicator of the stock market.

There is also a tutorial on bootstrapping and other resampling methods that includes a discussion of permutation tests.

There are print and plot methods for this class of object. The print method merely describes the object and shows the p-value of the test (rounded, by default, to 4 digits).

The p-value as given by the print method is simplified to be the number of random permutations that are at least as extreme as the original divided by the total number of random permutations. To be strictly correct, 1 should be added to both numerator and denominator. In general the difference is of no consequence. However, there are cases where it does matter, for example when independent p-values are combined.

Usage

permutation.test.discrete(x, y = NULL, scores, alternative = "greater", 
        trials = 1000)
permutation.test.fun(x, y = NULL, fun = function(x, y) sum(x * y), 
        alternative = "greater", trials = 1000)

Arguments

x either a two-column matrix or data frame, or a vector. When this has two columns, y should not be given.
y either a zero-length object, or a vector the same length as x.
scores a numeric matrix providing the scores for each combination of the unique values in x and y. The dimnames need to consist of these unique values.
fun a function that takes two arguments and returns a single numeric value.
alternative a character string that partially matches either "greater" or "less".
trials the number of random permutations to be performed.

Value

an object of class permtstBurSt which is a list with the following components:

original.score the score (or function value) produced by the original data.
perm.scores a vector of the scores (or function values) from the random permutations.
stats a numeric vector that has the number of observations in the data, the number of random permutations done, and the number of permutations that produced a score at least as extreme as the original.
alternative either "greater" or "less".
random.seed the random seed at the start of the call.
call an image of the call that was used.

Side effects

The object .Random.seed is either created or updated.

See Also

plot.permtstBurSt.

Examples

winner <- c('N', 'N', 'A', 'N', 'A', 'N')
market <- c('+', '-', '-', '+', '+', '+')
smat <- diag(2)
dimnames(smat) <- list(c('N', 'A'), c('+', '-'))

pt1 <- permutation.test.discrete(winner, market, smat)
print(pt1)
plot(pt1)

data(ToothGrowth)
pt2 <- permutation.test.fun(ToothGrowth[, -2], fun=cor)
print(pt2)
plot(pt2)

smat2 <- matrix(c(-3, -.5, 3, -1, 1, 0, 0, 1, -1, 3, -.5, -3),
        3, 4, dimnames=list(c('Up', 'Neut', 'Down'), 
        c('Q1', 'Q2', 'Q3', 'Q4')))
permutation.test.discrete(my.dataframe[, c("results", "quartile")], 
        score=smat2)


[Package Contents]