Compute the p-value of a Fisher randomization test.

fisher_pv(value, group, Tfun, nsim = 1000)

Arguments

value

Vector of length nobs corresponding to the values from which the test statistics is computed. That is, value[i] is the value corresponding to observation i.

group

Vector of length nobs indicating to which group each observation belongs. Group membership is determined from the elements of unique(group).

Tfun

Function taking vector arguments value and group, returning ntest test statistics.

nsim

Number of randomizations to perform.

Value

A two column matrix with ntest rows and columns:

Tobs

A vector of length ntest, where Tobs[t] is the observed value of test statistic t.

pval

A vector of ntest p-values of the form Pr(Tsim[t] > Tobs[t]), where Tobs[t] = Tfun(value, group)[t] and Tsim[t] is computed by randomly reallocating value to the given vector group.

Details

Suppose there is only one test statistic ntest = 1. Then the Fisher randomization test calculates

Pr(Tsim > Tobs),

where Tobs = Tfun(value, group) is the observed value of the test statistic, and Tsim = Tfun(value[irand], group), where irand is a random permutation of the nobs observations. When ntest > 1, fisher_pv() performs the calculation above for each test statistic.