R Under development (unstable) (2026-03-05 r89546) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu 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. > #### Some examples of the KS and Wilcoxon tests > > ### ------ Kolmogorov Smirnov (KS) -------------- > > ## unrealistic one of PR#14561 > ds1 <- c(1.7,2,3,3,4,4,5,5,6,6) > ks.test(ds1, "pnorm", mean = 3.3, sd = 1.55216) Asymptotic one-sample Kolmogorov-Smirnov test data: ds1 D = 0.274, p-value = 0.4407 alternative hypothesis: two-sided Warning message: In ks.test.default(ds1, "pnorm", mean = 3.3, sd = 1.55216) : ties should not be present for the one-sample Kolmogorov-Smirnov test > # how on earth can sigma = 1.55216 be known? > > # R >= 2.14.0 allows the equally invalid > ks.test(ds1, "pnorm", mean = 3.3, sd = 1.55216, exact = TRUE) Exact one-sample Kolmogorov-Smirnov test data: ds1 D = 0.274, p-value = 0.3715 alternative hypothesis: two-sided Warning message: In ks.test.default(ds1, "pnorm", mean = 3.3, sd = 1.55216, exact = TRUE) : ties should not be present for the one-sample Kolmogorov-Smirnov test > > ## Try out the effects of rounding > set.seed(123) > ds2 <- rnorm(1000) > ks.test(ds2, "pnorm") # exact = FALSE is default for n = 1000 Asymptotic one-sample Kolmogorov-Smirnov test data: ds2 D = 0.019416, p-value = 0.8452 alternative hypothesis: two-sided > ks.test(ds2, "pnorm", exact = TRUE) Exact one-sample Kolmogorov-Smirnov test data: ds2 D = 0.019416, p-value = 0.8379 alternative hypothesis: two-sided > ## next two are still close > ks.test(round(ds2, 2), "pnorm") Asymptotic one-sample Kolmogorov-Smirnov test data: round(ds2, 2) D = 0.019169, p-value = 0.856 alternative hypothesis: two-sided Warning message: In ks.test.default(round(ds2, 2), "pnorm") : ties should not be present for the one-sample Kolmogorov-Smirnov test > ks.test(round(ds2, 2), "pnorm", exact = TRUE) Exact one-sample Kolmogorov-Smirnov test data: round(ds2, 2) D = 0.019169, p-value = 0.8489 alternative hypothesis: two-sided Warning message: In ks.test.default(round(ds2, 2), "pnorm", exact = TRUE) : ties should not be present for the one-sample Kolmogorov-Smirnov test > # now D has doubled, but p-values remain similar (if very different from ds2) > ks.test(round(ds2, 1), "pnorm") Asymptotic one-sample Kolmogorov-Smirnov test data: round(ds2, 1) D = 0.03674, p-value = 0.1344 alternative hypothesis: two-sided Warning message: In ks.test.default(round(ds2, 1), "pnorm") : ties should not be present for the one-sample Kolmogorov-Smirnov test > ks.test(round(ds2, 1), "pnorm", exact = TRUE) Exact one-sample Kolmogorov-Smirnov test data: round(ds2, 1) D = 0.03674, p-value = 0.1311 alternative hypothesis: two-sided Warning message: In ks.test.default(round(ds2, 1), "pnorm", exact = TRUE) : ties should not be present for the one-sample Kolmogorov-Smirnov test > > > ### ------ Wilkoxon (Mann Whitney) -------------- > > options(nwarnings = 1000) > (alts <- setNames(, eval(formals(stats:::wilcox.test.default)$alternative))) two.sided less greater "two.sided" "less" "greater" > x0 <- 0:4 > (x.set <- list(s0 = lapply(x0, function(m) 0:m), + s. = lapply(x0, function(m) c(1e-9, seq_len(m))))) $s0 $s0[[1]] [1] 0 $s0[[2]] [1] 0 1 $s0[[3]] [1] 0 1 2 $s0[[4]] [1] 0 1 2 3 $s0[[5]] [1] 0 1 2 3 4 $s. $s.[[1]] [1] 1e-09 $s.[[2]] [1] 1e-09 1e+00 $s.[[3]] [1] 1e-09 1e+00 2e+00 $s.[[4]] [1] 1e-09 1e+00 2e+00 3e+00 $s.[[5]] [1] 1e-09 1e+00 2e+00 3e+00 4e+00 > stats <- setNames(nm = c("statistic", "p.value", "conf.int", "estimate")) > > ## Even with conf.int = TRUE, do not want errors : > RR <- + lapply(x.set, ## for all data sets + function(xs) + lapply(alts, ## for all three alternatives + function(alt) + lapply(xs, function(x) + ## try( + wilcox.test(x, exact=TRUE, conf.int=TRUE, alternative = alt) + ## ) + ))) > length(ww <- warnings()) # 52 (or 43 for x0 <- 0:3) [1] 1 > unique(ww) # 4 different ones Warning message: In ks.test.default(round(ds2, 1), "pnorm", exact = TRUE) : ties should not be present for the one-sample Kolmogorov-Smirnov test > > cc <- lapply(RR, function(A) lapply(A, function(bb) lapply(bb, class))) > table(unlist(cc)) htest 30 > ## in R <= 3.3.1, with try( .. ) above, we got > ## htest try-error > ## 23 7 > uc <- unlist(cc[["s0"]]); noquote(names(uc)[uc != "htest"]) ## these 7 cases : character(0) > ## two.sided1 two.sided2 two.sided3 > ## less1 less2 > ## greater1 greater2 > > ##--- How close are the stats of (0:m) to those of (eps, 1:m) ------------ > > ## a version that still works with above try(.) and errors there: > getC <- function(L, C) if(inherits(L,"try-error")) c(L) else L[[C]] > stR <- lapply(stats, function(COMP) + lapply(RR, function(A) + lapply(A, function(bb) + lapply(bb, getC, C=COMP) ))) > > ## a) P-value > pv <- stR[["p.value"]] > ## only the first is NaN, all others in [0,1]: > sapply(pv$s0, unlist) two.sided less greater [1,] 1.000 1 1.0000 [2,] 1.000 1 0.5000 [3,] 0.500 1 0.2500 [4,] 0.250 1 0.1250 [5,] 0.125 1 0.0625 > sapply(pv$s., unlist) # not really close, but .. two.sided less greater [1,] 1.0000 1 0.50000 [2,] 0.5000 1 0.25000 [3,] 0.2500 1 0.12500 [4,] 0.1250 1 0.06250 [5,] 0.0625 1 0.03125 > > pv$s0$two.sided[1] <- 1 ## artificially > stopifnot(all.equal(pv$s0, pv$s., tolerance = 0.5 + 1e-6), # seen 0.5 + ## "less" are close: + all.equal(unlist(pv[[c("s0","less")]]), + unlist(pv[[c("s.","less")]]), + tolerance = 0.03), + 0 <= unlist(pv), unlist(pv) <= 1) # <- no further NA .. > ## b) > sapply(stR[["statistic"]], unlist) s0 s. two.sided.V 0 1 two.sided.V 2 3 two.sided.V 5 6 two.sided.V 9 10 two.sided.V 14 15 less.V 0 1 less.V 2 3 less.V 5 6 less.V 9 10 less.V 14 15 greater.V 0 1 greater.V 2 3 greater.V 5 6 greater.V 9 10 greater.V 14 15 > ## Conf.int.: > ## c) > sapply(stR[["estimate" ]], unlist) s0 s. two.sided.(pseudo)median 0.0 1.0e-09 two.sided.(pseudo)median 0.5 5.0e-01 two.sided.(pseudo)median 1.0 1.0e+00 two.sided.(pseudo)median 1.5 1.5e+00 two.sided.(pseudo)median 2.0 2.0e+00 less.(pseudo)median 0.0 1.0e-09 less.(pseudo)median 0.5 5.0e-01 less.(pseudo)median 1.0 1.0e+00 less.(pseudo)median 1.5 1.5e+00 less.(pseudo)median 2.0 2.0e+00 greater.(pseudo)median 0.0 1.0e-09 greater.(pseudo)median 0.5 5.0e-01 greater.(pseudo)median 1.0 1.0e+00 greater.(pseudo)median 1.5 1.5e+00 greater.(pseudo)median 2.0 2.0e+00 > ## d) confidence interval > formatCI <- function(ci) + sprintf("[%g, %g] (%g%%)", ci[[1]], ci[[2]], + round(100*attr(ci,"conf.level"))) > nx <- length(x0) > noquote(vapply(stR[["conf.int"]], function(ss) + vapply(ss, function(alt) vapply(alt, formatCI, ""), character(nx)), + matrix("", nx, length(alts)))) , , s0 two.sided less greater [1,] [0, Inf] (100%) [-Inf, Inf] (100%) [0, Inf] (100%) [2,] [0, Inf] (100%) [-Inf, Inf] (100%) [0, Inf] (100%) [3,] [0, Inf] (100%) [-Inf, Inf] (100%) [0, Inf] (100%) [4,] [0, Inf] (100%) [-Inf, Inf] (100%) [0, Inf] (100%) [5,] [0, Inf] (100%) [-Inf, 4] (100%) [0.5, Inf] (97%) , , s. two.sided less greater [1,] [-Inf, Inf] (100%) [-Inf, Inf] (100%) [-Inf, Inf] (100%) [2,] [-Inf, Inf] (100%) [-Inf, Inf] (100%) [-Inf, Inf] (100%) [3,] [-Inf, Inf] (100%) [-Inf, Inf] (100%) [-Inf, Inf] (100%) [4,] [-Inf, Inf] (100%) [-Inf, Inf] (100%) [-Inf, Inf] (100%) [5,] [-Inf, Inf] (100%) [-Inf, 4] (97%) [1e-09, Inf] (97%) > > > ##-------- 2-sample tests (working unchanged) ------------------ > > R2 <- lapply(alts, ## for all three alternatives + function(alt) + lapply(seq_along(x0), function(k) + wilcox.test(x = x.set$s0[[k]], y = x.set$s.[[k]], + exact=TRUE, conf.int=TRUE, alternative = alt))) > length(w2 <- warnings()) # 27 [1] 1 > unique(w2) # 3 different ones Warning message: In ks.test.default(round(ds2, 1), "pnorm", exact = TRUE) : ties should not be present for the one-sample Kolmogorov-Smirnov test > > table(uc2 <- unlist(c2 <- lapply(R2, function(A) lapply(A, class)))) htest 15 > stopifnot(uc2 == "htest") > > stR2 <- lapply(stats, + function(COMP) + lapply(R2, function(A) lapply(A, getC, C=COMP))) > > lapply(stats[-3], ## -3: "conf.int" separately + function(ST) sapply(stR2[[ST]], unlist)) $statistic two.sided less greater W 0.0 0.0 0.0 W 1.5 1.5 1.5 W 4.0 4.0 4.0 W 7.5 7.5 7.5 W 12.0 12.0 12.0 $p.value two.sided less greater [1,] 1.0000000 0.5000000 1.0000000 [2,] 1.0000000 0.5000000 0.8333333 [3,] 1.0000000 0.5000000 0.7000000 [4,] 0.9714286 0.4857143 0.6285714 [5,] 0.9682540 0.4841270 0.5873016 $estimate two.sided less greater difference in location -1e-09 -1e-09 -1e-09 difference in location -5e-10 -5e-10 -5e-10 difference in location 0e+00 0e+00 0e+00 difference in location 0e+00 0e+00 0e+00 difference in location 0e+00 0e+00 0e+00 > > noquote(sapply(stR2[["conf.int"]], function(.) vapply(., formatCI, ""))) two.sided less greater [1,] [-Inf, Inf] (100%) [-Inf, Inf] (100%) [-Inf, Inf] (100%) [2,] [-Inf, Inf] (100%) [-Inf, Inf] (100%) [-Inf, Inf] (100%) [3,] [-Inf, Inf] (100%) [-Inf, 2] (100%) [-2, Inf] (100%) [4,] [-3, 3] (100%) [-Inf, 2] (97%) [-2, Inf] (97%) [5,] [-3, 3] (96%) [-Inf, 2] (95%) [-2, Inf] (97%) > > > proc.time() user system elapsed 0.237 0.012 0.240