|
12 | 12 | # Set up |
13 | 13 | # |
14 | 14 |
|
15 | | -# Skip these tests on Apple M1 mac |
16 | | -skip_on_os("mac", arch = "aarch64") |
17 | | - |
18 | 15 | context("corTestDS::smk::setup") |
19 | 16 |
|
20 | 17 | # |
@@ -201,7 +198,32 @@ test_that("simple corTestDS, some, with na, pearson", { |
201 | 198 |
|
202 | 199 | expect_equal(class(res$`Correlation test`$statistic), "numeric") |
203 | 200 | expect_length(res$`Correlation test`$statistic, 1) |
204 | | - expect_true(is.infinite(res$`Correlation test`$statistic[[1]])) |
| 201 | + |
| 202 | + # extract information from the results |
| 203 | + t_stat <- res$`Correlation test`$statistic[[1]] |
| 204 | + df <- res$`Number of pairwise complete cases` |
| 205 | + # re-calculate the value for r (correlation) |
| 206 | + ## t_stat <- sqrt(df) * r / sqrt(1 - r^2) # Equation 1 |
| 207 | + ## calculate intermediate coefficient, derived from Equation 1 |
| 208 | + A <- t_stat / sqrt(df) |
| 209 | + ## use the intermediate value to estimate the correlation value, r |
| 210 | + r <- sqrt(A^2 / (1 + A^2)) |
| 211 | + |
| 212 | + # if testing on Apple M1: due to numeric precision |
| 213 | + if (getElement(Sys.info(), "sysname") == "Darwin" && |
| 214 | + getElement(R.version, "arch") == "aarch64") { |
| 215 | + # lower tolerance, expect failure, due to numeric precision |
| 216 | + expect_error(expect_equal(r, 1L, tolerance = 1E-16)) |
| 217 | + # higher tolerance, expect success |
| 218 | + expect_equal(r, 1L, tolerance = 1E-8) |
| 219 | + } |
| 220 | + else { # other architectures |
| 221 | + expect_true(is.infinite(res$`Correlation test`$statistic[[1]])) |
| 222 | + # lower tolerance, expect success |
| 223 | + expect_equal(r, 1L, tolerance = 1E-16) |
| 224 | + # higher tolerance, expect success |
| 225 | + expect_equal(r, 1L, tolerance = 1E-8) |
| 226 | + } |
205 | 227 |
|
206 | 228 | expect_equal(class(res$`Correlation test`$parameter), "integer") |
207 | 229 | expect_length(res$`Correlation test`$parameter, 1) |
@@ -611,3 +633,4 @@ test_that("simple corTestDS, some, with na, spearman", { |
611 | 633 | context("corTestDS::smk::shutdown") |
612 | 634 |
|
613 | 635 | context("corTestDS::smk::done") |
| 636 | + |
0 commit comments