Skip to content

Commit

Permalink
fix: ensure p-values are null if the t_statistic is null
Browse files Browse the repository at this point in the history
  • Loading branch information
zietzm committed Jul 22, 2024
1 parent 8e41042 commit ddb3755
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/stats/sumstats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit ddb3755

Please sign in to comment.