Distributions.jl icon indicating copy to clipboard operation
Distributions.jl copied to clipboard

Add mean et al. for truncated log normal

Open ararslan opened this issue 1 year ago • 7 comments

This PR adds mgf for truncated normal and uses that to implement mean, var, skewness, and kurtosis for truncated log normal based on this observation. ~~median is also implemented for truncated log normal.~~

Fixes #709

ararslan avatar Jun 26 '24 02:06 ararslan

My worry (that was also expressed in issues such as https://github.com/JuliaStats/Distributions.jl/issues/968) is that generally numerical integration is challenging and a fallback might lead to silently incorrect results. It seems such a fallback would be wrong (or at least problematic) e.g. if the moments are not finite (such as e.g. for Cauchy).

So my general feeling is that numerical integration should maybe be restricted to a smaller subset of distributions, or maybe even only be available as a separate function. In case we want to use it more broadly, I think it would also be safer to error if the integration error estimate is too large, to reduce the probability of silently incorrect results.

devmotion avatar Jun 26 '24 07:06 devmotion

@devmotion Is there any numerical integration in this code?

PaulSoderlind avatar Jun 26 '24 14:06 PaulSoderlind

@devmotion, perhaps you're thinking of #1875? As @PaulSoderlind noted, there's no integration here.

ararslan avatar Jun 26 '24 15:06 ararslan

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.71%. Comparing base (65f056c) to head (70c7810). Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1874      +/-   ##
==========================================
- Coverage   85.99%   85.71%   -0.29%     
==========================================
  Files         144      145       +1     
  Lines        8666     8706      +40     
==========================================
+ Hits         7452     7462      +10     
- Misses       1214     1244      +30     

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

codecov-commenter avatar Jun 27 '24 01:06 codecov-commenter

Oh yes, indeed, it seems I commented on the wrong PR.

devmotion avatar Jun 27 '24 13:06 devmotion

CI failures on nightly are unrelated.

ararslan avatar Jun 28 '24 20:06 ararslan

Ugh, type inference issue on 1.3 and I can't test on 1.3 locally 😑

ararslan avatar Jun 29 '24 01:06 ararslan