libcoin/0000755000176200001440000000000015156000460011666 5ustar liggesuserslibcoin/tests/0000755000176200001440000000000014172231233013031 5ustar liggesuserslibcoin/tests/bugfixes.R0000644000176200001440000000374714172231233015003 0ustar liggesusers library("libcoin") ### by Henric Winell set.seed(29) X <- runif(10) Y <- runif(10) o <- LinStatExpCov(X, Y) ov <- LinStatExpCov(X, Y, varonly = TRUE) stopifnot(all.equal(doTest(o, teststat = "scalar"), doTest(ov, teststat = "scalar"))) ### all weights = 0 and no weights at all was treated the same X <- as.double(1:10) Y <- as.double(10:1) sum(X*Y) cl <- gl(2, 5) ### linstat = 220 w <- as.integer(rep(1, 10)) LinStatExpCov(X = X, Y = Y) LinStatExpCov(X = X, Y = Y, weights = w) LinStatExpCov(X = X, Y = Y, weights = w, block = cl) ### linstat = 0 w <- as.integer(rep(0, 10)) LinStatExpCov(X = X, Y = Y, weights = w) LinStatExpCov(X = X, Y = Y, weights = w, block = cl) ### linstat = 110 w <- as.integer(rep(0, 10)) w[1:5] <- 1L LinStatExpCov(X = X, Y = Y, subset = 1:5) LinStatExpCov(X = X, Y = Y, weights = w) LinStatExpCov(X = X, Y = Y, weights = w, block = cl) ### linstat = 0 LinStatExpCov(X = X, Y = Y, weights = w, subset = 6:10) LinStatExpCov(X = X, Y = Y, weights = w, block = cl, subset = 6:10) ### missing values in 1d and 2d case x <- gl(6, 20) y <- gl(3, 40) x[sample(1:length(x), 10)] <- NA y[sample(1:length(y), 10)] <- NA X <- matrix(NA, nrow = length(x), ncol = nlevels(x)) X[!is.na(x),] <- model.matrix(~ x - 1) Y <- matrix(NA, nrow = length(y), ncol = nlevels(y)) Y[!is.na(y),] <- model.matrix(~ y - 1) lev1 <- LinStatExpCov(X = X, Y = Y) lev1$Sumweights t1 <- doTest(lev1, teststat = "quadratic") X <- rbind(0, diag(nlevels(x))) Y <- rbind(0, diag(nlevels(y))) ix <- unclass(x) ix[is.na(ix)] <- 0L iy <- unclass(y) iy[is.na(iy)] <- 0L levels(ix) <- levels(x) levels(iy) <- levels(y) lev2 <- LinStatExpCov(X = X, Y = Y, ix = ix, iy = iy) lev2$Sumweights t2 <- doTest(lev2, teststat = "quadratic") stopifnot(all.equal(t1, t2)) ### unnecessary memory allocation; fixed in 1.0-2 N <- 146341L y <- runif(N) x <- 1:N lev1 <- LinStatExpCov(X = x, Y = y, varonly = TRUE) # Note: N * (N + 1) / 2 > .Machine$integer.max try(lev2 <- LinStatExpCov(X = x, Y = y, varonly = FALSE)) libcoin/tests/regtest_ctabs.R0000644000176200001440000000156614172231233016015 0ustar liggesusers library("libcoin") x <- 1:6 y <- rep(1:3, length.out = 6) w <- rep(2L, length(x)) b <- gl(2, 3) s <- 1:4 ctabs(x) ctabs(x, weights = w) ctabs(x, subset = s) ctabs(x, weights = w, subset = s) ctabs(x, block = b) ctabs(x, weights = w, block = b) ctabs(x, subset = s, block = b) ctabs(x, weights = w, subset = s, block = b) ctabs(x, y) ctabs(x, y, weights = w) ctabs(x, y, subset = s) ctabs(x, y, weights = w, subset = s) ctabs(x, y, block = b) ctabs(x, y, weights = w, block = b) ctabs(x, y, subset = s, block = b) ctabs(x, y, weights = w, subset = s, block = b) w <- round(1:length(x) / length(x), 2) ctabs(x, weights = w) ctabs(x, weights = w, subset = s) ctabs(x, weights = w, block = b) ctabs(x, weights = w, subset = s, block = b) ctabs(x, y, weights = w) ctabs(x, y, weights = w, subset = s) ctabs(x, y, weights = w, block = b) ctabs(x, y, weights = w, subset = s, block = b) libcoin/tests/regtest_ctabs.Rout.save0000644000176200001440000001415514172231233017500 0ustar liggesusers R Under development (unstable) (2017-12-04 r73829) -- "Unsuffered Consequences" Copyright (C) 2017 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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("libcoin") > > x <- 1:6 > y <- rep(1:3, length.out = 6) > w <- rep(2L, length(x)) > b <- gl(2, 3) > s <- 1:4 > > ctabs(x) [1] 0 1 1 1 1 1 1 > ctabs(x, weights = w) [1] 0 2 2 2 2 2 2 > ctabs(x, subset = s) [1] 0 1 1 1 1 0 0 > ctabs(x, weights = w, subset = s) [1] 0 2 2 2 2 0 0 > ctabs(x, block = b) [,1] [,2] [1,] 0 0 [2,] 1 0 [3,] 1 0 [4,] 1 0 [5,] 0 1 [6,] 0 1 [7,] 0 1 > ctabs(x, weights = w, block = b) [,1] [,2] [1,] 0 0 [2,] 2 0 [3,] 2 0 [4,] 2 0 [5,] 0 2 [6,] 0 2 [7,] 0 2 > ctabs(x, subset = s, block = b) [,1] [,2] [1,] 0 0 [2,] 1 0 [3,] 1 0 [4,] 1 0 [5,] 0 1 [6,] 0 0 [7,] 0 0 > ctabs(x, weights = w, subset = s, block = b) [,1] [,2] [1,] 0 0 [2,] 2 0 [3,] 2 0 [4,] 2 0 [5,] 0 2 [6,] 0 0 [7,] 0 0 > > ctabs(x, y) [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 1 0 0 [3,] 0 0 1 0 [4,] 0 0 0 1 [5,] 0 1 0 0 [6,] 0 0 1 0 [7,] 0 0 0 1 > ctabs(x, y, weights = w) [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 2 0 0 [3,] 0 0 2 0 [4,] 0 0 0 2 [5,] 0 2 0 0 [6,] 0 0 2 0 [7,] 0 0 0 2 > ctabs(x, y, subset = s) [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 1 0 0 [3,] 0 0 1 0 [4,] 0 0 0 1 [5,] 0 1 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 > ctabs(x, y, weights = w, subset = s) [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 2 0 0 [3,] 0 0 2 0 [4,] 0 0 0 2 [5,] 0 2 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 > ctabs(x, y, block = b) , , 1 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 1 0 0 [3,] 0 0 1 0 [4,] 0 0 0 1 [5,] 0 0 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 , , 2 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0 [4,] 0 0 0 0 [5,] 0 1 0 0 [6,] 0 0 1 0 [7,] 0 0 0 1 > ctabs(x, y, weights = w, block = b) , , 1 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 2 0 0 [3,] 0 0 2 0 [4,] 0 0 0 2 [5,] 0 0 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 , , 2 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0 [4,] 0 0 0 0 [5,] 0 2 0 0 [6,] 0 0 2 0 [7,] 0 0 0 2 > ctabs(x, y, subset = s, block = b) , , 1 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 1 0 0 [3,] 0 0 1 0 [4,] 0 0 0 1 [5,] 0 0 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 , , 2 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0 [4,] 0 0 0 0 [5,] 0 1 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 > ctabs(x, y, weights = w, subset = s, block = b) , , 1 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 2 0 0 [3,] 0 0 2 0 [4,] 0 0 0 2 [5,] 0 0 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 , , 2 [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0 [4,] 0 0 0 0 [5,] 0 2 0 0 [6,] 0 0 0 0 [7,] 0 0 0 0 > > w <- round(1:length(x) / length(x), 2) > ctabs(x, weights = w) [1] 0.00 0.17 0.33 0.50 0.67 0.83 1.00 > ctabs(x, weights = w, subset = s) [1] 0.00 0.17 0.33 0.50 0.67 0.00 0.00 > ctabs(x, weights = w, block = b) [,1] [,2] [1,] 0.00 0.00 [2,] 0.17 0.00 [3,] 0.33 0.00 [4,] 0.50 0.00 [5,] 0.00 0.67 [6,] 0.00 0.83 [7,] 0.00 1.00 > ctabs(x, weights = w, subset = s, block = b) [,1] [,2] [1,] 0.00 0.00 [2,] 0.17 0.00 [3,] 0.33 0.00 [4,] 0.50 0.00 [5,] 0.00 0.67 [6,] 0.00 0.00 [7,] 0.00 0.00 > > ctabs(x, y, weights = w) [,1] [,2] [,3] [,4] [1,] 0 0.00 0.00 0.0 [2,] 0 0.17 0.00 0.0 [3,] 0 0.00 0.33 0.0 [4,] 0 0.00 0.00 0.5 [5,] 0 0.67 0.00 0.0 [6,] 0 0.00 0.83 0.0 [7,] 0 0.00 0.00 1.0 > ctabs(x, y, weights = w, subset = s) [,1] [,2] [,3] [,4] [1,] 0 0.00 0.00 0.0 [2,] 0 0.17 0.00 0.0 [3,] 0 0.00 0.33 0.0 [4,] 0 0.00 0.00 0.5 [5,] 0 0.67 0.00 0.0 [6,] 0 0.00 0.00 0.0 [7,] 0 0.00 0.00 0.0 > ctabs(x, y, weights = w, block = b) , , 1 [,1] [,2] [,3] [,4] [1,] 0 0.00 0.00 0.0 [2,] 0 0.17 0.00 0.0 [3,] 0 0.00 0.33 0.0 [4,] 0 0.00 0.00 0.5 [5,] 0 0.00 0.00 0.0 [6,] 0 0.00 0.00 0.0 [7,] 0 0.00 0.00 0.0 , , 2 [,1] [,2] [,3] [,4] [1,] 0 0.00 0.00 0 [2,] 0 0.00 0.00 0 [3,] 0 0.00 0.00 0 [4,] 0 0.00 0.00 0 [5,] 0 0.67 0.00 0 [6,] 0 0.00 0.83 0 [7,] 0 0.00 0.00 1 > ctabs(x, y, weights = w, subset = s, block = b) , , 1 [,1] [,2] [,3] [,4] [1,] 0 0.00 0.00 0.0 [2,] 0 0.17 0.00 0.0 [3,] 0 0.00 0.33 0.0 [4,] 0 0.00 0.00 0.5 [5,] 0 0.00 0.00 0.0 [6,] 0 0.00 0.00 0.0 [7,] 0 0.00 0.00 0.0 , , 2 [,1] [,2] [,3] [,4] [1,] 0 0.00 0 0 [2,] 0 0.00 0 0 [3,] 0 0.00 0 0 [4,] 0 0.00 0 0 [5,] 0 0.67 0 0 [6,] 0 0.00 0 0 [7,] 0 0.00 0 0 > > proc.time() user system elapsed 0.288 0.052 0.333 libcoin/tests/Examples/0000755000176200001440000000000014341133054014607 5ustar liggesuserslibcoin/tests/Examples/libcoin-Ex.Rout.save0000644000176200001440000000527514341133054020421 0ustar liggesusers R Under development (unstable) (2022-10-11 r83083 ucrt) -- "Unsuffered Consequences" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) 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. Natural language support but running in an English locale 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. > pkgname <- "libcoin" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > options(pager = "console") > library('libcoin') > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("LinStatExpCov") > ### * LinStatExpCov > > flush(stderr()); flush(stdout()) > > ### Name: LinStatExpCov > ### Title: Linear Statistics with Expectation and Covariance > ### Aliases: LinStatExpCov lmult > ### Keywords: htest > > ### ** Examples > > wilcox.test(Ozone ~ Month, data = airquality, subset = Month %in% c(5, 8), + exact = FALSE, correct = FALSE) Wilcoxon rank sum test data: Ozone by Month W = 127.5, p-value = 0.0001164 alternative hypothesis: true location shift is not equal to 0 > > aq <- subset(airquality, Month %in% c(5, 8)) > X <- as.double(aq$Month == 5) > Y <- as.double(rank(aq$Ozone, na.last = "keep")) > doTest(LinStatExpCov(X, Y)) $TestStatistic [1] 3.853635 $p.value [1] 0.0001163773 > > > > cleanEx() > nameEx("ctabs") > ### * ctabs > > flush(stderr()); flush(stdout()) > > ### Name: ctabs > ### Title: Cross Tabulation > ### Aliases: ctabs > ### Keywords: univar > > ### ** Examples > > ctabs(ix = 1:5, iy = 1:5, weights = 1:5 / 5) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 0.0 0.0 0.0 0.0 0 [2,] 0 0.2 0.0 0.0 0.0 0 [3,] 0 0.0 0.4 0.0 0.0 0 [4,] 0 0.0 0.0 0.6 0.0 0 [5,] 0 0.0 0.0 0.0 0.8 0 [6,] 0 0.0 0.0 0.0 0.0 1 > > > > ### *