From 88832b9f2c641c7c9a57f90848f3bd92a383f39d Mon Sep 17 00:00:00 2001 From: zietzm Date: Tue, 23 Jul 2024 19:19:03 -0500 Subject: [PATCH] fix: allow bad degrees-of-freedom chore: bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/stats/sumstats.rs | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13292f5..f1c38a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,7 +337,7 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "igwas" -version = "1.0.9" +version = "1.0.10" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index bd40c60..16c40eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "igwas" -version = "1.0.9" +version = "1.0.10" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 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 }