R Under development (unstable) (2023-10-04 r85267 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(matrixTests) > source("utils/capture.r") > > #--- x has less than 1 observation --------------------------------------------- > > wrn <- 'row_wilcoxon_twosample: 1 of the rows had less than 1 "x" observation.\nFirst occurrence at row 1' > nacolumns <- c("statistic", "pvalue") > > # 0 observations > res <- capture(row_wilcoxon_twosample(numeric(), 1)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 0)) > stopifnot(all.equal(res$value$obs.tot, 1)) > > # only NA observations > res <- capture(row_wilcoxon_twosample(c(NA_integer_, NA_integer_), 1)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 0)) > stopifnot(all.equal(res$value$obs.tot, 1)) > > > #--- y has less than 1 observations -------------------------------------------- > > wrn <- 'row_wilcoxon_twosample: 1 of the rows had less than 1 "y" observation.\nFirst occurrence at row 1' > nacolumns <- c("statistic", "pvalue") > > # 0 observations > res <- capture(row_wilcoxon_twosample(1, numeric())) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.y, 0)) > stopifnot(all.equal(res$value$obs.tot, 1)) > > # only NA observations > res <- capture(row_wilcoxon_twosample(1, c(NA_integer_, NA_integer_))) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.y, 0)) > stopifnot(all.equal(res$value$obs.tot, 1)) > > > #--- both x and y have less than 1 observation --------------------------------- > > wrnx <- 'row_wilcoxon_twosample: 1 of the rows had less than 1 "x" observation.\nFirst occurrence at row 1' > wrny <- 'row_wilcoxon_twosample: 1 of the rows had less than 1 "y" observation.\nFirst occurrence at row 1' > nacolumns <- c("statistic", "pvalue") > > # 0 observations > res <- capture(row_wilcoxon_twosample(numeric(), numeric())) > stopifnot(all.equal(res$warning[1:2], c(wrnx, wrny))) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 0)) > stopifnot(all.equal(res$value$obs.y, 0)) > stopifnot(all.equal(res$value$obs.tot, 0)) > > # only NA observations > res <- capture(row_wilcoxon_twosample(c(NA_integer_, NA_integer_), c(NA_integer_, NA_integer_))) > stopifnot(all.equal(res$warning[1:2], c(wrnx, wrny))) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 0)) > stopifnot(all.equal(res$value$obs.y, 0)) > stopifnot(all.equal(res$value$obs.tot, 0)) > > > #--- ties are present ---------------------------------------------------------- > > wrn <- 'row_wilcoxon_twosample: 1 of the rows had ties: cannot compute exact p-values with ties.\nFirst occurrence at row 1' > > # warning when exact=TRUE > res <- capture(row_wilcoxon_twosample(c(3,3,1,2), c(2,0,5,-2), exact=TRUE)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all.equal(res$value$exact, FALSE)) > stopifnot(all.equal(res$value$obs.x, 4)) > stopifnot(all.equal(res$value$obs.y, 4)) > stopifnot(all.equal(res$value$obs.tot, 8)) > > # no warning when exact=FALSE > res <- capture(row_wilcoxon_twosample(c(3,3,1,2), c(2,0,5,-2), exact=FALSE)) > stopifnot(all.equal(res$warning, NULL)) > stopifnot(all.equal(res$value$exact, FALSE)) > stopifnot(all.equal(res$value$obs.x, 4)) > stopifnot(all.equal(res$value$obs.y, 4)) > stopifnot(all.equal(res$value$obs.tot, 8)) > > # ties only after subtracting null > res <- capture(row_wilcoxon_twosample(c(3.1,4,1,2), c(-1,-2,3,-4), null=0.1, exact=TRUE)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all.equal(res$value$exact, FALSE)) > stopifnot(all.equal(res$value$obs.x, 4)) > stopifnot(all.equal(res$value$obs.y, 4)) > stopifnot(all.equal(res$value$obs.tot, 8)) > > > proc.time() user system elapsed 0.14 0.07 0.20