From eb17449093b14d719e4ed7e15580384d10d0868c Mon Sep 17 00:00:00 2001 From: Robbie McKinstry Date: Fri, 29 Nov 2024 18:42:49 -0500 Subject: [PATCH] Attempt to catch error where NaN is introduced. --- src/stats/chi.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/stats/chi.rs b/src/stats/chi.rs index b867050..ea07c45 100644 --- a/src/stats/chi.rs +++ b/src/stats/chi.rs @@ -25,12 +25,22 @@ fn test_statistic>(table: &ContingencyTable f64 { + if expected_count == 0 { + 1.0 + } else { + expected_count as f64 + } +} + /// calculates the p-value given the test statistic and the degrees of freedom. /// This is determined by the area of the Chi Square distribution (which is a special /// case of the gamma distribution).