diff --git a/src/stats/sumstats.rs b/src/stats/sumstats.rs index d376d94..0208e50 100644 --- a/src/stats/sumstats.rs +++ b/src/stats/sumstats.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use statrs::distribution::ContinuousCDF; use statrs::distribution::StudentsT; @@ -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 }