From dea74fe5fd06a7778c3f8d1d636f8661de2a372c Mon Sep 17 00:00:00 2001 From: skymanbp <57272723+skymanbp@users.noreply.github.com> Date: Mon, 24 Aug 2026 03:24:48 -0400 Subject: [PATCH] fix: compute skewness as g1 --- .../src-internal/DataFrame/Internal/Statistics.hs | 2 +- tests/Operations/Statistics.hs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dataframe-operations/src-internal/DataFrame/Internal/Statistics.hs b/dataframe-operations/src-internal/DataFrame/Internal/Statistics.hs index 0c80ad4a..8f6fcbe3 100644 --- a/dataframe-operations/src-internal/DataFrame/Internal/Statistics.hs +++ b/dataframe-operations/src-internal/DataFrame/Internal/Statistics.hs @@ -106,7 +106,7 @@ skewnessStep (SkewAcc !n !meanVal !m2 !m3) !x' = computeSkewness :: SkewAcc -> Double computeSkewness (SkewAcc n _ m2 m3) | n < 3 = 0 -- or error "skewness of <3 samples" - | otherwise = (sqrt (fromIntegral n - 1) * m3) / sqrt (m2 ^ (3 :: Int)) + | otherwise = (sqrt (fromIntegral n) * m3) / sqrt (m2 ^ (3 :: Int)) {-# INLINE computeSkewness #-} skewness' :: (VU.Unbox a, Real a, Num a) => VU.Vector a -> Double diff --git a/tests/Operations/Statistics.hs b/tests/Operations/Statistics.hs index db907654..1f0d804a 100644 --- a/tests/Operations/Statistics.hs +++ b/tests/Operations/Statistics.hs @@ -56,6 +56,7 @@ skewnessOfSymmetricDataSet = 0 ) +-- g1, matching scipy.stats.skew skewnessOfSimpleDataSet :: Test skewnessOfSimpleDataSet = TestCase @@ -63,7 +64,7 @@ skewnessOfSimpleDataSet = "Skewness of a simple data set" ( abs ( D.skewness' (VU.fromList [25 :: Int, 28, 26, 30, 40, 50, 40]) - - 0.566_731_633_676 + - 0.612_140_127_240_396_6 ) < 1e-12 )