cdf of binomial and Poisson interpolates between integers at a non-integer point instead of flooring, so P(X<=2.5) is 0.102 instead of 0.0547

Open
#357 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start by locating the cdf implementations for the binomial and Poisson distributions, then compare them with the negative binomial implementation, which the issue says already floors non-integer inputs. Check the existing tests for these distributions and add cases at non-integer values such as 2.5 and 3.5. Done means those cases return the CDF at the floored integer, matching the expected values in the issue.

Written by the indexing model from the issue text.

Description

area/statistics good first issue help wanted kind/wrong-result severity/2-critical

cdf of the discrete families is evaluated as if the distribution were continuous: at a non-integer point it interpolates between the two neighbouring integers instead of returning P(X <= floor(x)). R and every discrete CDF definition floor the argument, so the returned probability is wrong.

library(rssn)
a <- compute(parse_term("cdf(binomial_dist(10,1/2), 2.5)"))
a$text    # "0.10201547808034023"
a$value   # 0.10201547808034

compute(parse_term("cdf(poisson(5/2), 3.5)"))$value   # 0.834308260193408
compute(parse_term("cdf(binomial_dist(10,1/2), 2)"))$value   # 0.0546875  (correct, at an integer)

The correct answers are P(X <= 2.5) = P(X <= 2) = pbinom(2, 10, 1/2) = 0.0546875 and P(X <= 3.5) = P(X <= 3) = ppois(3, 2.5) = 0.7575761. rssn instead returns values strictly between the two integer steps: for binomial(10, 1/2) the sequence is 0.05476 (x=2.001), 0.10202 (x=2.5), 0.17171 (x=2.999), i.e. it is a smooth interpolation, not a step function.

The interpolation is exactly the continuous incomplete-beta/gamma formula I_{1-p}(n-x, x+1) evaluated at the real x:

R> pbeta(0.5, 7.5, 3.5)      # binomial(10,1/2) "cdf" at x=2.5
[1] 0.1020155

negative_binomial already floors correctly (cdf(negative_binomial(5,1/2), 4.5) is 0.5, the value at 4), so the two discrete kernels are inconsistent with each other as well as with R.

Expected: cdf of a discrete distribution at a non-integer x should return the value at floor(x); e.g. cdf(binomial_dist(10,1/2), 2.5) = 0.0546875 and cdf(poisson(5/2), 3.5) = 0.7575761.

rssn 0.3.0, R 4.6.2 binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

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.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.