Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Statistics/Test/KruskalWallis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ kruskalWallisRank samples = groupByTags

-- | The Kruskal-Wallis Test.
--
-- In textbooks the output value is usually represented by 'K' or 'H'. This
-- function already does the ranking.
-- In textbooks the output value is usually represented by 'K' or
-- 'H'. This function already does the ranking. This function returns
-- NaN in case when all values in sample are identical.
kruskalWallis :: (U.Unbox a, Ord a) => [U.Vector a] -> Double
kruskalWallis samples = (nTot - 1) * numerator / denominator
where
Expand All @@ -77,11 +78,16 @@ kruskalWallis samples = (nTot - 1) * numerator / denominator
-- significance. For additional information check 'kruskalWallis'. This is just
-- a helper function.
--
-- It uses /Chi-Squared/ distribution for approximation as long as the sizes are
-- larger than 5. Otherwise the test returns 'Nothing'.
-- It uses /Chi-Squared/ distribution for approximation as long as the
-- sizes are larger than 5. Otherwise the test returns 'Nothing'. In
-- case when all elements in all samples are identical test value
-- couldn't be computed and @Nothing@ is returned.
kruskalWallisTest :: (Ord a, U.Unbox a) => [U.Vector a] -> Maybe (Test ())
kruskalWallisTest [] = Nothing
kruskalWallisTest [_] = Nothing
kruskalWallisTest samples
-- NaN is returned when all values in all samples are identical.
| isNaN k = Nothing
-- We use chi-squared approximation here
| all (>4) ns = Just Test { testSignificance = mkPValue $ complCumulative d k
, testStatistics = k
Expand Down
8 changes: 7 additions & 1 deletion tests/Tests/NonParametric.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ kruskalWallisTests = zipWith test [(0::Int)..] testData
, 6.10
, Just Significant
)
, ( [ [6, 6, 6, 6, 6]
, [6, 6, 6, 6, 6, 6, 6, 6]
, [6, 6, 6, 6, 6, 6]
]
, 0.0 / 0.0 -- this should equal NaN as all the samples are the same.
, Nothing
)
]


----------------------------------------------------------------
-- K-S test
----------------------------------------------------------------
Expand Down
Loading