Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: permutation test #157

Open
GregorySchwartz opened this issue Sep 19, 2019 · 4 comments
Open

Feature request: permutation test #157

GregorySchwartz opened this issue Sep 19, 2019 · 4 comments

Comments

@GregorySchwartz
Copy link

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

@Shimuuar
Copy link
Collaborator

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

@GregorySchwartz
Copy link
Author

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.

@GregorySchwartz
Copy link
Author

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

@GregorySchwartz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants