Skip to content

Commit

Permalink
fix precision issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lassedochreden committed Oct 8, 2024
1 parent b71d2f0 commit cb91faf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions tests/testthat/test_integration_interactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit cb91faf

Please sign in to comment.