Statistics.Test.MannWhitneyU

statistics-0.13.3.0: A library of statistical types, data, and functions

Copyright | (c) 2010 Neil Brown
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

Statistics.Test.MannWhitneyU

Contents

- Mann-Whitney U test
  - Wilcoxon rank sum test
- Data types
- References

Description

Mann-Whitney U test (also know as Mann-Whitney-Wilcoxon and Wilcoxon rank sum test) is a non-parametric test for assesing whether two samples of independent observations have different mean.

Synopsis

- mannWhitneyUtest :: TestType -> Double -> Sample -> Sample -> Maybe TestResult
- mannWhitneyU :: Sample -> Sample -> (Double, Double)
- mannWhitneyUCriticalValue :: (Int, Int) -> Double -> Maybe Int
- mannWhitneyUSignificant :: TestType -> (Int, Int) -> Double -> (Double, Double) -> Maybe TestResult
- wilcoxonRankSums :: Sample -> Sample -> (Double, Double)
- data TestType
  - = OneTailed
  - | TwoTailed
- data TestResult
  - = Significant
  - | NotSignificant

# Mann-Whitney U test

mannWhitneyUtest #

Arguments

:: TestType | Perform one-tailed test (see description above).
-> Double | The p-value at which to test (e.g. 0.05)
-> Sample | First sample
-> Sample | Second sample
-> Maybe TestResult | Return `Nothing` if the sample was too small to make a decision.

Perform Mann-Whitney U Test for two samples and required significance. For additional information check documentation of `mannWhitneyU` and `mannWhitneyUSignificant`. This is just a helper function.

One-tailed test checks whether first sample is significantly larger than second. Two-tailed whether they are significantly different.

mannWhitneyU :: Sample -> Sample -> (Double, Double) #

The Mann-Whitney U Test.

This is sometimes known as the Mann-Whitney-Wilcoxon U test, and confusingly many sources state that the Mann-Whitney U test is the same as the Wilcoxon's rank sum test (which is provided as `wilcoxonRankSums`). The Mann-Whitney U is a simple transform of Wilcoxon's rank sum test.

Again confusingly, different sources state reversed definitions for U₁ and U₂, so it is worth being explicit about what this function returns. Given two samples, the first, xs₁, of size n₁ and the second, xs₂, of size n₂, this function returns (U₁, U₂) where U₁ = W₁ - (n₁(n₁+1))/2 and U₂ = W₂ - (n₂(n₂+1))/2, where (W₁, W₂) is the return value of `wilcoxonRankSums xs1 xs2`.

Some sources instead state that U₁ and U₂ should be the other way round, often expressing this using U₁' = n₁n₂ - U₁ (since U₁ + U₂ = n₁n₂).

All of which you probably don't care about if you just feed this into `mannWhitneyUSignificant`.

mannWhitneyUCriticalValue #

Arguments

:: (Int, Int) | The sample size
-> Double | The p-value (e.g. 0.05) for which you want the critical value.
-> Maybe Int | The critical value (of U).

Calculates the critical value of Mann-Whitney U for the given sample sizes and significance level.

This function returns the exact calculated value of U for all sample sizes; it does not use the normal approximation at all. Above sample size 20 it is generally recommended to use the normal approximation instead, but this function will calculate the higher critical values if you need them.

The algorithm to generate these values is a faster, memoised version of the simple unoptimised generating function given in section 2 of "The Mann Whitney Wilcoxon Distribution Using Linked Lists"

mannWhitneyUSignificant #

Arguments

:: TestType | Perform one-tailed test (see description above).
-> (Int, Int) | The samples' size from which the (U₁,U₂) values were derived.
-> Double | The p-value at which to test (e.g. 0.05)
-> (Double, Double) | The (U₁, U₂) values from `mannWhitneyU`.
-> Maybe TestResult | Return `Nothing` if the sample was too small to make a decision.

Calculates whether the Mann Whitney U test is significant.

If both sample sizes are less than or equal to 20, the exact U critical value (as calculated by `mannWhitneyUCriticalValue`) is used. If either sample is larger than 20, the normal approximation is used instead.

If you use a one-tailed test, the test indicates whether the first sample is significantly larger than the second. If you want the opposite, simply reverse the order in both the sample size and the (U₁, U₂) pairs.

## Wilcoxon rank sum test

wilcoxonRankSums :: Sample -> Sample -> (Double, Double) #

The Wilcoxon Rank Sums Test.

This test calculates the sum of ranks for the given two samples. The samples are ordered, and assigned ranks (ties are given their average rank), then these ranks are summed for each sample.

The return value is (W₁, W₂) where W₁ is the sum of ranks of the first sample and W₂ is the sum of ranks of the second sample. This test is trivially transformed into the Mann-Whitney U test. You will probably want to use `mannWhitneyU` and the related functions for testing significance, but this function is exposed for completeness.

# Data types

data TestType #

Test type. Exact meaning depends on a specific test. But generally it's tested whether some statistics is too big (small) for `OneTailed` or whether it too big or too small for `TwoTailed`

Constructors

OneTailed |
TwoTailed |

Instances

Eq TestType # |
Methods (==) :: TestType -> TestType -> Bool # (/=) :: TestType -> TestType -> Bool #
Data TestType # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TestType -> c TestType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TestType # toConstr :: TestType -> Constr # dataTypeOf :: TestType -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c TestType) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestType) # gmapT :: (forall b. Data b => b -> b) -> TestType -> TestType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TestType -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TestType -> r # gmapQ :: (forall d. Data d => d -> u) -> TestType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TestType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TestType -> m TestType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TestType -> m TestType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TestType -> m TestType #
Ord TestType # |
Methods compare :: TestType -> TestType -> Ordering # (<) :: TestType -> TestType -> Bool # (<=) :: TestType -> TestType -> Bool # (>) :: TestType -> TestType -> Bool # (>=) :: TestType -> TestType -> Bool # max :: TestType -> TestType -> TestType # min :: TestType -> TestType -> TestType #
Show TestType # |
Methods showsPrec :: Int -> TestType -> ShowS # show :: TestType -> String # showList :: [TestType] -> ShowS #
Generic TestType # |
Associated Types type Rep TestType :: * -> * # Methods from :: TestType -> Rep TestType x # to :: Rep TestType x -> TestType #
ToJSON TestType # |
Methods toJSON :: TestType -> Value # toEncoding :: TestType -> Encoding #
FromJSON TestType # |
Methods parseJSON :: Value -> Parser TestType #
type Rep TestType # |
type Rep TestType = D1 (MetaData "TestType" "Statistics.Test.Types" "statistics-0.13.3.0-116AMxscZNKCm819FAiSIF" False) ((:+:) (C1 (MetaCons "OneTailed" PrefixI False) U1) (C1 (MetaCons "TwoTailed" PrefixI False) U1))

data TestResult #

Result of hypothesis testing

Constructors

Significant | Null hypothesis should be rejected
NotSignificant | Data is compatible with hypothesis

Instances

Eq TestResult # |
Methods (==) :: TestResult -> TestResult -> Bool # (/=) :: TestResult -> TestResult -> Bool #
Data TestResult # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TestResult -> c TestResult # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TestResult # toConstr :: TestResult -> Constr # dataTypeOf :: TestResult -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c TestResult) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestResult) # gmapT :: (forall b. Data b => b -> b) -> TestResult -> TestResult # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TestResult -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TestResult -> r # gmapQ :: (forall d. Data d => d -> u) -> TestResult -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TestResult -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TestResult -> m TestResult # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TestResult -> m TestResult # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TestResult -> m TestResult #
Ord TestResult # |
Methods compare :: TestResult -> TestResult -> Ordering # (<) :: TestResult -> TestResult -> Bool # (<=) :: TestResult -> TestResult -> Bool # (>) :: TestResult -> TestResult -> Bool # (>=) :: TestResult -> TestResult -> Bool # max :: TestResult -> TestResult -> TestResult # min :: TestResult -> TestResult -> TestResult #
Show TestResult # |
Methods showsPrec :: Int -> TestResult -> ShowS # show :: TestResult -> String # showList :: [TestResult] -> ShowS #
Generic TestResult # |
Associated Types type Rep TestResult :: * -> * # Methods from :: TestResult -> Rep TestResult x # to :: Rep TestResult x -> TestResult #
ToJSON TestResult # |
Methods toJSON :: TestResult -> Value # toEncoding :: TestResult -> Encoding #
FromJSON TestResult # |
Methods parseJSON :: Value -> Parser TestResult #
type Rep TestResult # |
type Rep TestResult = D1 (MetaData "TestResult" "Statistics.Test.Types" "statistics-0.13.3.0-116AMxscZNKCm819FAiSIF" False) ((:+:) (C1 (MetaCons "Significant" PrefixI False) U1) (C1 (MetaCons "NotSignificant" PrefixI False) U1))

# References

- Cheung, Y.K.; Klotz, J.H. (1997) The Mann Whitney Wilcoxon distribution using linked lists. Statistica Sinica 7:805–813. http://www3.stat.sinica.edu.tw/statistica/oldpdf/A7n316.pdf.