From ddb3755ce86897661d8d0814d7d36d94f63ad1fe Mon Sep 17 00:00:00 2001 From: zietzm Date: Mon, 22 Jul 2024 08:54:49 -0500 Subject: [PATCH] fix: ensure p-values are null if the t_statistic is null --- src/stats/sumstats.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 + } + } }