Feature request: permutation test
This should be relatively straightforward to implement: type permutationTest :: (v a -> v b -> Double) -> Int -> PValue, i.e. takes in a function that takes a vector of labels and a vector of samples to report a test statistic, a number of random runs, and returns the p-value (possibly with the observed test statistic of the samples with labels).
I don't understand what this test should do. Function with provided signature could only compute PValue from Int and doesn't seems to be useful
You're absolutely right. I meant:
permutationTest :: (v a -> v b -> Double) -> Int -> v a -> v b -> PValue
That is, (function of labels, samples to test statistic) -> number of runs -> labels -> samples -> p-value.
It would be basically (with mwc-random):
-- | Permutation test returning p-value.
permutationTest :: (G.Vector v a, G.Vector v b)
=> (v a -> v b -> Double)
-> Int
-> v a
-> v b
-> IO Double
permutationTest f runs labs samples = do
let obs = f labs samples
run r = do
g <- R.initialize . V.singleton $ fromIntegral r
ls <- R.uniformShuffle labs g
return $ f ls samples
n <- genericLength . filter (>= obs) <$> mapM run [1..runs]
return $ n / fromIntegral runs
Although it should be permutationTest :: (v a -> b -> Double) -> Int -> v a -> b -> PValue to generalize the sample structure (it could be a matrix or tree, for instance).