Skip to content

Conversation

@PraneyaKumar
Copy link
Contributor

Summary

Changes

  • New Modules:
    • Statistics.Test.Bartlett
    • Statistics.Test.Levene
  • Added these modules to the exposed-modules section in the statistics.cabal file.
  • Documentation:
    • Usage examples in Haddock comments.
  • Updated the changelog.md to reflect the addition.

Notes for Reviewers

  • This is my first contribution to the library. Feedback on:
    • Numerical stability improvements
    • Error handling patterns
    • Test coverage
    • Any improvements needed in the code structure or style

Copy link
Collaborator

@Shimuuar Shimuuar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR! I'll be busy whole April and will need to read about both tests. So thing will probably move slowly.

There're few comments on things that caught my eye,

-- Degrees of freedom and chi-squared distribution
df = k - 1
chiDist = chiSquared df
pValue = mkPValue $ 1 - cumulative chiDist tStatistic
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complCumulative should calculates 1-CDF without loss of precision

AFAIR χ² doesn't implement it but it may at some point

zbari = map Sample.mean deviations
zbar = sum (zipWith (*) zbari (map fromIntegral ni)) / fromIntegral n

numerator = sum [fromIntegral (ni !! i) * (zbari !! i - zbar) ** 2 | i <- [0..k-1]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! is generally smell since it's O(n). zbari and ni should probably be vector

@PraneyaKumar
Copy link
Contributor Author

Hi @Shimuuar!

Thanks for the helpful feedback!

  1. complCumulative – I noticed that chiSquared currently doesn’t implement complCumulative. So for now, I’ve added a TODO comment in the code noting that this could be replaced with complCumulative when it becomes available.

  2. Avoiding !! – I've refactored the levenesTest implementation to use boxed Vectors (Data.Vector) and replaced the list-indexing logic with Vector.zipWith and Vector.sum. This should be more idiomatic and efficient. Let me know if any further improvements are needed on this part.

Thanks again, and no worries at all about things moving slowly — I really appreciate your time and review whenever you get a chance.

Copy link
Collaborator

@Shimuuar Shimuuar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general PR is fine.

complCumulative – I noticed that chiSquared currently doesn’t implement complCumulative. So for now, I’ve added a TODO comment in the code noting that this could be replaced with complCumulative when it becomes available.

It's not implemented so default implementation will be used instead. And if class method gets implemented it will be used automatically, no need to change anything in test implementation.


Please also add simple unit test in Tests.Parametric that checks both test compute approximately same test statistics and p-value as python/R/whatever.

levenesTest :: Double -- ^ Significance level (alpha)
-> Center -- ^ Center calculation method
-> [V.Vector Double] -- ^ Input samples
-> Either String TestResult
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function should return Statistics.Test.Types.Test as Bartlett do,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now reworked Levene's Test to return Test instead of TestResult.

@PraneyaKumar
Copy link
Contributor Author

In general PR is fine.

complCumulative – I noticed that chiSquared currently doesn’t implement complCumulative. So for now, I’ve added a TODO comment in the code noting that this could be replaced with complCumulative when it becomes available.

It's not implemented so default implementation will be used instead. And if class method gets implemented it will be used automatically, no need to change anything in test implementation.

Please also add simple unit test in Tests.Parametric that checks both test compute approximately same test statistics and p-value as python/R/whatever.

Hi @Shimuuar!

I've pushed the requested changes:

  • Reworked Levene's Test to return Test instead of TestResult.
  • Added unit test for Bartlett's and Levene's test in Tests.Parametric, verifying the test statistic and p-value against reference values.

Please let me know if any further adjustments are needed!

@Shimuuar
Copy link
Collaborator

Well. It needs quite a bit of improvements but it would be easier to just merge it as is and fix it later

@Shimuuar Shimuuar merged commit ff92091 into haskell:master Jun 29, 2025
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

Successfully merging this pull request may close these issues.

Add tests of homoscedasticity

2 participants