permutation.test.discrete {BurStMisc} | R Documentation |

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

```
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)
```

`x` |
either a two-column matrix or data frame, or a vector.
When this has two columns, |

`y` |
either a zero-length object, or a vector the same length as |

`scores` |
a numeric matrix providing the scores for each combination of
the unique values in |

`fun` |
a function that takes two arguments and returns a single numeric value. |

`alternative` |
a character string that partially matches either |

`trials` |
the number of random permutations to be performed. |

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, the number of permutations that produced a score at least as extreme as the original, and the p-value for the test. |

`alternative` |
either |

`random.seed` |
the random seed at the start of the call. |

`call` |
an image of the call that was used. |

The object `.Random.seed`

is either created or updated.

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).

A simple version of the p-value is the number of random permutations that are at least as extreme as the original divided by the total number of random permutations. The value computed, which is more correct, has 1 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.

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 permutation tests via a discussion of the Super Bowl indicator of the stock market.

```
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)
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')))
my.results <- data.frame(results=sample(c('Up', 'Neut', 'Down'),
100, replace=TRUE), quartile=sample(
c('Q1', 'Q2', 'Q3', 'Q4'), 100, replace=TRUE))
permutation.test.discrete(my.results[, c("results", "quartile")],
score=smat2)
```

[Package *BurStMisc* version 1.1 Index]