JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.
Other
1.1k stars 414 forks source link

Fix inconsistent return types of `quantile` etc. #1805

Open devmotion opened 10 months ago

devmotion commented 10 months ago

Currently, the return type of quantile etc. is inconsistent, in particular for discrete distributions. For many distributions (and in particular those for which we fall back to StatsFuns/Rmath) the return type is explicitly to converted to Int to match the type of the variates. However, the behaviour of some distributions such as Geometric or Bernoulli is inconsistent: The return type of quantile does not match the type of the variates.

This PR fixes the inconsistency. Moreover, I added tests to avoid regressions and made an existing test a bit stricter. These tests revealed a few additional problems (e.g. caused by the Rmath behaviour that StatsFuns.RFunctions.binominvcdf(10, 1.0, 0.0) = 0 and StatsFuns.RFunctions.hyperinvlogccdf(2, 2, 2, -Inf) = NaN which so far we have hidden by skipping them in the tests).

Fixes #1798.

codecov-commenter commented 6 days ago

Codecov Report

Attention: Patch coverage is 94.85294% with 7 lines in your changes missing coverage. Please review.

Project coverage is 86.29%. Comparing base (a1010e4) to head (8345f1c).

Files with missing lines Patch % Lines
src/univariate/discrete/bernoullilogit.jl 0.00% 4 Missing :warning:
src/univariate/discrete/negativebinomial.jl 87.50% 2 Missing :warning:
src/univariate/discrete/binomial.jl 97.36% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1805 +/- ## ========================================== + Coverage 86.08% 86.29% +0.21% ========================================== Files 144 144 Lines 8696 8788 +92 ========================================== + Hits 7486 7584 +98 + Misses 1210 1204 -6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.