-
Notifications
You must be signed in to change notification settings - Fork 19
Description
There seems to be a bug in SiegelTukeyRank that is causing SiegelTukeyTest to be incorrect. Here is an example:
y <- c(-1, 2, 2.1, 3)
x <- c(-5, -9, 13, 12, 90, 100)
jmuOutlier::siegel.test(x - median(x), y - median(y)) #matches by hand calculation p = 0.1142857
DescTools::SiegelTukeyTest(x - median(x), y - median(y)) #p = 0.8571
DescTools::SiegelTukeyTest(x, y, adjust.median = T) #p = 0.8571
On further inspection, SiegelTukeyRank seems to be the issue, as it discards 3 values. Piping the results of SiegelTukeyRank to SiegelTukeyTest gives the same p-value as a direct application.
DescTools::SiegelTukeyRank(c(x - median(x), y - median(y)), g = rep(letters[1:2], times = c(6, 4)))
DescTools::SiegelTukeyRank(c(x - median(x), y - median(y)), g = rep(letters[1:2], times = c(6, 4))) |>
with(wilcox.test(unique.ranks ~ sort.id)) #p = 0.8571
This is "fixed" by rounding.
DescTools::SiegelTukeyRank(round(c(x - median(x), y - median(y)), 3), g = rep(letters[1:2], times = c(6, 4)))
DescTools::SiegelTukeyTest(round(c(x - median(x), y - median(y)), 3) ~ rep(letters[1:2], times = c(6, 4))) # p = 0.1143
The problem seems to be in the merge used to define ST.matrix after using as.numeric(as.character(names(unique.ranks))), which due to numerical precision issues in floats caused there to be non-matches that were thrown away. I updated to most recent R release and DescTools package, and the problem persists. Thanks for your work on this package and for reading!
Find my session info below:
R version 4.5.1 (2025-06-13)
Platform: x86_64-apple-darwin20
Running under: macOS Sequoia 15.4.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Chicago
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DescTools_0.99.60 lubridate_1.9.4 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.1.0 readr_2.1.5 tidyr_1.3.1 tibble_3.3.0 ggplot2_3.5.2
[11] tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] generics_0.1.4 class_7.3-23 stringi_1.8.7 lattice_0.22-7 hms_1.1.3 magrittr_2.0.3 grid_4.5.1 timechange_0.3.0 RColorBrewer_1.1-3
[10] mvtnorm_1.3-3 cellranger_1.1.0 Matrix_1.7-3 e1071_1.7-16 httr_1.4.7 scales_1.4.0 cli_3.6.5 rlang_1.1.6 expm_1.0-0
[19] withr_3.0.2 rootSolve_1.8.2.4 tools_4.5.1 tzdb_0.5.0 lmom_3.2 gld_2.6.7 Exact_3.3 boot_1.3-31 vctrs_0.6.5
[28] R6_2.6.1 proxy_0.4-27 lifecycle_1.0.4 jmuOutlier_2.2 fs_1.6.6 MASS_7.3-65 pkgconfig_2.0.3 pillar_1.11.0 gtable_0.3.6
[37] data.table_1.17.8 glue_1.8.0 Rcpp_1.1.0 haven_2.5.5 tidyselect_1.2.1 rstudioapi_0.17.1 farver_2.1.2 compiler_4.5.1 readxl_1.4.5