From cb91faf50b4364c88ebb7ed38dc9829edfc06c31 Mon Sep 17 00:00:00 2001 From: lassedochreden Date: Tue, 8 Oct 2024 14:53:18 +0200 Subject: [PATCH] fix precision issues in tests --- DESCRIPTION | 2 +- NEWS | 3 +++ tests/testthat/test_integration_interactions.R | 10 ++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cdd7977..1a51adb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: imcRtools -Version: 1.11.1 +Version: 1.11.2 Title: Methods for imaging mass cytometry data analysis Description: This R package supports the handling and analysis of imaging mass cytometry diff --git a/NEWS b/NEWS index f9d83af..4c96e17 100644 --- a/NEWS +++ b/NEWS @@ -227,3 +227,6 @@ Changes in version 1.11.1 (2024-10-03) + fixed BiocNeighbors error for DFrame type data +Changes in version 1.11.2 (2024-10-08) + ++ fixed testInteraction and countInteraction tests due to machine precision issues diff --git a/tests/testthat/test_integration_interactions.R b/tests/testthat/test_integration_interactions.R index 1f14115..f6701b7 100644 --- a/tests/testthat/test_integration_interactions.R +++ b/tests/testthat/test_integration_interactions.R @@ -167,10 +167,12 @@ calc_p_vals<- function(dat_baseline, dat_perm, n_perm, p_tresh=0.01){ dat_perm[, ':='(ct_perm=replace(ct_perm, is.na(ct_perm), 0), ct_obs=replace(ct_obs, is.na(ct_obs), 0) )] - - - dat_stat = dat_perm[ , .(p_gt=ifelse(max(ct_obs)==0, 1,(sum(ct_perm>=ct_obs)+1)/(n_perm+1)), - p_lt=(n_perm-sum(ct_perm>ct_obs)+1)/(n_perm+1)) , by=.(group, FirstLabel, SecondLabel)] + # We introduced a more lenient way of checking equality to avoid issues + # with machine precision + tolerance <- sqrt(.Machine$double.eps) + dat_stat <- dat_perm[ , .(p_gt = ifelse(max(ct_obs) == 0, 1, (sum((ct_perm - ct_obs) > -tolerance) + 1) / (n_perm + 1)), + p_lt = (n_perm - sum((ct_perm - ct_obs) > tolerance) + 1) / (n_perm + 1)), + by=.(group, FirstLabel, SecondLabel)] dat_stat[, direction := p_gt < p_lt] dat_stat[, p := p_gt * direction + p_lt * (direction == FALSE)]