diff --git a/src/stats/sumstats.rs b/src/stats/sumstats.rs index 73b152d..d376d94 100644 --- a/src/stats/sumstats.rs +++ b/src/stats/sumstats.rs @@ -5,8 +5,13 @@ pub fn compute_neg_log_pvalue(t_statistic: f32, degrees_of_freedom: i32) -> f32 let t = t_statistic as f64; let dof = degrees_of_freedom as f64; - let t_dist = StudentsT::new(0.0, 1.0, dof).unwrap(); - let p = 2.0 * t_dist.cdf(-t.abs()); - - -p.log10() as f32 + match t { + 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(); + let p = 2.0 * t_dist.cdf(-t.abs()); + -p.log10() as f32 + } + } }