Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add moments for distributions of order statistics #1950

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sethaxen
Copy link
Contributor

@sethaxen sethaxen commented Feb 25, 2025

This PR implements moments for OrderStatistic and JointOrderStatistics. These are useful for some statistical tests and for computation of L-moments.

Features

  • Exact mean, var, cov, skewness, and kurtosis for order statistics of Uniform and Exponential
  • Exact mean and var for order statistics of Logistic
  • Exact mean for order statistics of Normal when n<=5
  • Numerically integrated marginal moments for all continuous order statistics
  • Exact moments for discrete order statistics with finite support and approximate for those with infinite support on the integers.
  • Tests

Example

Here's a basic implementation of L-moments:

function lmoment(d::UnivariateDistribution, p::Integer)
    p > 0 || throw(ArgumentError("p must be a positive integer"))
    p == 1 && return mean(d)
    ranks = 1:p
    coefs = @. binomial(p - 1, ranks - 1) * (-1) ^ ranks
    if d isa ContinuousUnivariateDistribution
        means = mean(JointOrderStatistics(d, p, ranks; check_args=false))
    else
        means = mean.(OrderStatistic.(d, p, ranks; check_args=false))
    end
    return (coefs' * means) / p
end
julia> lmoment.(Uniform(0, 10), 1:4)  [5, 10/6, 0, 0]
true

@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 0% with 292 lines in your changes missing coverage. Please review.

Project coverage is 83.42%. Comparing base (e470421) to head (e8ad400).

Files with missing lines Patch % Lines
src/univariate/orderstatistic.jl 0.00% 168 Missing ⚠️
src/multivariate/jointorderstatistics.jl 0.00% 124 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1950      +/-   ##
==========================================
- Coverage   86.19%   83.42%   -2.78%     
==========================================
  Files         146      146              
  Lines        8768     9060     +292     
==========================================
  Hits         7558     7558              
- Misses       1210     1502     +292     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

2 participants