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

Inverse cdf inconsistency with cdf for the gamma distibution #200

Closed
RonBarakBackal opened this issue Feb 14, 2024 · 1 comment · Fixed by #227
Closed

Inverse cdf inconsistency with cdf for the gamma distibution #200

RonBarakBackal opened this issue Feb 14, 2024 · 1 comment · Fixed by #227

Comments

@RonBarakBackal
Copy link

First of all, thank you for making this crate! I have been working in R and MATLAB and searched for a Rust crate.

When I run the cdf function of gamma with parameters shape = 3, rate = 0.5, to x = 20.5567 in R, MATLAB, or Rust (using statrs) the answer is identical:
0.997796914589247

But inversing it in R and Matlab results in very accurate 20.5567000...
while running this code :

use statrs::distribution::{Gamma, Continuous,ContinuousCDF};
use statrs::statistics::Distribution;
let gamma_dist = Gamma::new(3.0,0.5).unwrap();
let x = gamma_dist.cdf(20.5567);
let t = gamma_dist.inverse_cdf(x);
println!("{}",x);
println!("{}",t);

gives for the inverse:
20.556948....
Which is relatively high error

Thanks a lot and have a great day!
Ron

@YeungOnion
Copy link
Contributor

Thinking we could implement up to convergence with a higher upper iteration bound, or perhaps we could change to another algorithm:

  • brent bisection
  • newton raphson as we know the derivative, just need a way to handle not going out of $p \in (0,1)$ and potentially causing a logical loop, perhaps bisect a few steps first?

ref: scipy implementation

@YeungOnion YeungOnion linked a pull request May 4, 2024 that will close this issue
YeungOnion added a commit that referenced this issue May 24, 2024
YeungOnion added a commit that referenced this issue May 24, 2024
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 a pull request may close this issue.

2 participants