stan-dev / stan-dev/math

[FR] Add order statistics pdf

Open
#2,605 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

distributions good first issue
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Description

When we do CDF regressions, the order statistic pdf updates the target density with the appropriate change of variables. There are 2 possible parameterizations. One involving the k_th order statistic and one involving the quantile. I'm interesting in the quantile version but it's quite easy to swap out since you can swap out k_i with nq_i in the following

image
from https://arxiv.org/pdf/2008.06423.pdf.

Example

The code is quite simple given a CDF transformed vector U (i.e. U = F(x) where F(*) is a CDF), a vector of the corresponding quantiles, and the total sample size N (where size(U) can be << N):

 real orderstatistics_lpdf(vector U, data vector q, int N){
        int M = num_elements(q);
        real lpdf = lgamma(N + 1) - lgamma(N * q[1]) - lgamma(N * (1 - q[M]) + 1); // normalizing constant
        lpdf += (N * q[1] - 1) * log(U[1]);
        lpdf += N * (1 - q[M]) * log1m(U[M]);
        
        for (m in 2:M) {
            lpdf += -lgamma(N * (q[m] - q[m - 1])); // normalizing constant
            lpdf += (N * (q[m] - q[m - 1]) - 1) * log(U[m] - U[m - 1]); 
        }
        return lpdf;
    }

I'm assuming q is always data so the derivative is wrt to U. I have it on paper but will add to this post later.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named in the issue. Start with the proposed orderstatistics_lpdf entry point and compare its quantile parameterization with the linked paper and stated change-of-variables assumptions. Done means the requested order-statistic PDF is added with derivatives taken with respect to U.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.