StudentsT inverse_cdf is broken
scullionw opened this issue · comments
William Scullion commented
It is currently only valid for ranges .25-0.5 and .75-1, which is probably why the tests don't catch it.
use statrs::distribution::{ContinuousCDF, StudentsT};
fn t_ppf(q: f64, freedom: f64, location: f64, scale: f64) -> f64 {
StudentsT::new(location, scale, freedom)
.unwrap()
.inverse_cdf(q)
}
fn main() {
let mut x = 0.01;
while x < 1.0 {
let y = t_ppf(x, 2.74, 0.0, 1.0);
debug_plotter::plot!((x, y));
x += 0.01
}
}
it should look like this:
I currently fix it in my code with
fn t_ppf(q: f64, freedom: f64, location: f64, scale: f64) -> f64 {
let candidate = StudentsT::new(location, scale, freedom)
.unwrap()
.inverse_cdf(q);
if q < 0.25 {
candidate * -1.0
} else if q < 0.5 {
candidate
} else if q < 0.75 {
candidate * -1.0
} else {
candidate
}
}
Warren Weckesser commented
I create a pull request with a fix: #159.