We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f5a1e8b commit 4196ba6Copy full SHA for 4196ba6
R/hierarchical_mutual_information.R
@@ -185,7 +185,7 @@ CharAMI <- function(char, tree, Mean = function(charH, treeH) charH,
185
num <- mi - emi[[1]]
186
denom <- M - emi[[1]]
187
# Return:
188
- structure(if (num < sqrt(.Machine$double.eps)) 0 else num / denom,
+ structure(if (abs(num) < sqrt(.Machine$double.eps)) 0 else num / denom,
189
sem = .AHMISEM(mi, M, emi[[1]], attr(emi, "sem")))
190
}
191
tests/testthat/test-charmi.R
@@ -99,7 +99,18 @@ test_that("AHMI succeeds with CharMI", {
99
CharEMI(ch, tr, precision = 0.001)[[1]], tolerance = 0.02)
100
101
expect_lt(CharAMI(ch, tr, max), CharAMI(ch, tr, min))
102
- expect_equal(CharAMI(c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), tr, min)[[1]], 0)
+ expect_lt(CharAMI(c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), tr, min)[[1]], 0)
103
expect_equal(CharAMI(c(1, 1, rep(0, 9)), tr)[[1]], 1)
104
expect_equal(CharAMI(c(rep(TRUE, 6), rep(FALSE, 5)), tr, min)[[1]], 1)
105
})
106
+
107
+test_that("AHMI returns zero for random trees", {
108
+ ch <- c(1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L)
109
+ tree <- TreeTools::NJTree(TreeTools::StringToPhyDat("12222211111"))
110
+ expect_gt(CharAMI(ch, tree), 0)
111
+ set.seed(1)
112
+ samples <- replicate(256, CharAMI(ch, TreeTools::RandomTree(ch)))
113
+ ci <- t.test(samples, mu = 0, conf.level = 0.997)$conf.int
114
+ expect_lt(ci[[1]], 0)
115
+ expect_gt(ci[[2]], 0)
116
+})
0 commit comments