Skip to content

Commit

Permalink
fix: allow bad degrees-of-freedom
Browse files Browse the repository at this point in the history
  • Loading branch information
zietzm committed Jul 24, 2024
1 parent e9ef32f commit d0ede13
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/stats/sumstats.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Context;
use statrs::distribution::ContinuousCDF;
use statrs::distribution::StudentsT;

Expand All @@ -9,7 +10,12 @@ pub fn compute_neg_log_pvalue(t_statistic: f32, degrees_of_freedom: i32) -> f32
f if f.is_nan() => f32::NAN,
f if f.is_infinite() => f32::INFINITY,
_ => {
let t_dist = StudentsT::new(0.0, 1.0, dof).unwrap();
if dof <= 1.0 {
return f32::NAN;
}
let t_dist = StudentsT::new(0.0, 1.0, dof)
.with_context(|| format!("Failed to compute t-statistic for dof {}", dof))
.unwrap();
let p = 2.0 * t_dist.cdf(-t.abs());
-p.log10() as f32
}
Expand Down

0 comments on commit d0ede13

Please sign in to comment.