R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.0 (2005-10-06 r35749) ISBN 3-900051-07-0 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 a HTML browser interface to help. Type 'q()' to quit R. > > ### Regression tests for fixed bugs > > set.seed(290875) > library(coin) Loading required package: survival Loading required package: splines Loading required package: mvtnorm Loading required package: modeltools > isequal <- coin:::isequal > > ### I() returns objects of class AsIs which caused an error in `trafo' > df <- data.frame(x1 = rnorm(100), x2 = rnorm(100), x3 = gl(2, 50)) > independence_test(I(x1 / x2) ~ x3, data = df) Asymptotic General Independence Test data: I(x1/x2) by groups 1, 2 T = -0.4491, p-value = 0.6534 alternative hypothesis: two.sided > independence_test(I(x1 < 0) ~ x3, data = df) Asymptotic General Independence Test data: I(x1 < 0) by groups 1, 2 T = 0.7966, p-value = 0.4257 alternative hypothesis: two.sided > > ### expectation was wrong when varonly = TRUE in case both > ### xtrafo and ytrafo were multivariate > if (require(multcomp)) { + df <- data.frame(x = runif(30), y = runif(30), z = gl(3, 10)) + a <- independence_test(x + y ~ z, data = df, + distribution = approximate(B = 19999), + xtrafo = function(data) trafo(data, factor_trafo = function(x) + model.matrix(~x - 1) %*% t(contrMat(table(x), "Tukey")))) + b <- independence_test(x + y ~ z, data = df, + xtrafo = function(data) trafo(data, factor_trafo = function(x) + model.matrix(~x - 1) %*% t(contrMat(table(x), "Tukey")))) + isequal(expectation(a), expectation(b)) + } Loading required package: multcomp [1] TRUE > > > ### `statistic' for linear and standardized statistics was wrong in case of > ### scores > data("jobsatisfaction") > stopifnot(unique(dim(statistic(lbl_test(jobsatisfaction), "linear"))) == 1) > stopifnot(unique(dim(statistic(lbl_test(jobsatisfaction), "standardized"))) == 1) > > > ### support() failed in most cases > df <- data.frame(x = runif(20), y = runif(20), z = gl(2, 10)) > support(independence_test(x ~ z, data = df)) [1] -4.264891 4.264891 > support(independence_test(x ~ z, data = df, teststat = "quad")) [1] 0.00000 19.51142 > ite <- independence_test(I(round(x, 1)) ~ z, data = df, dist = exact()) > ae <- support(ite) > de <- sapply(ae, function(x) dperm(ite, x)) > sum(de) [1] 1 > ita <- independence_test(I(round(x, 1)) ~ z, data = df, + dist = approximate(B = 100000)) > aa <- support(ita) > da <- sapply(aa, function(x) dperm(ita, x)) > sum(da) [1] 1 > mean(round(ae, 10) %in% aa) [1] 1 > > plot(aa, da, type = "s", lty = 1) > lines(ae, de, type = "s", lty = 2) > itas <- independence_test(I(round(x, 1)) ~ z, data = df) > lines(ae[-1], diff(sapply(ae, function(x) pperm(itas, x))), lty = 3) > legend("topleft", lty = 1:3, legend = c("approx", "exact", "asympt"), bty = "n") > > ### check correct handling of multiple censoring indicators (in modeltools) > ### was never wrong, just in case... > data("photocar", package = "coin") > i1 <- independence_test(Surv(time, event) + Surv(dmin, tumor) + ntumor ~ group, + data = photocar) > i2 <- independence_test(Surv(time, event) ~ group, data = photocar) > i3 <- independence_test(Surv(dmin, tumor) ~ group, data = photocar) > > stopifnot(max(abs(statistic(i1, "standardized")[,1] - + statistic(i2, "stand"))) < sqrt(.Machine$double.eps)) > stopifnot(max(abs(statistic(i1, "standardized")[,2] - + statistic(i3, "stand"))) < sqrt(.Machine$double.eps)) > > ### check new var_trafo argument > x <- rnorm(20) > y <- gl(2, 10) > a <- trafo(data.frame(x = x, y = y), numeric_trafo = normal_trafo) > b <- trafo(data.frame(x = x, y = y), var_trafo = list(x = normal_trafo)) > stopifnot(all.equal(a, b)) > > ### check for multiple ordered factors > mydf <- data.frame(x = ordered(gl(4, 5)), y = ordered(gl(5, 4)), + z = rnorm(20)) > try(independence_test(x + y ~ z , data = mydf)) Error in .local(.Object, ...) : handling of multiple ordered factors currently not implemented > try(independence_test(x + z ~ y , data = mydf)) Error in .local(.Object, ...) : handling of multiple ordered factors currently not implemented > try(independence_test(z ~ x + y , data = mydf)) Error in .local(.Object, ...) : handling of multiple ordered factors currently not implemented > > ### NA's and weights > mydf <- data.frame(x = 1:10, y = gl(2, 5), w = rep(2, 10)) > s <- statistic(independence_test(x ~ y, data = mydf, weights = ~ w), "linear") > stopifnot(s == 30) > mydf$x[1] <- NA > s <- statistic(independence_test(x ~ y, data = mydf, weights = ~ w), "linear") > stopifnot(s == 28) > > ### two observations only > mydf <- data.frame(x = 1:10, y = gl(2, 5)) > independence_test(y ~ x, data = mydf, subset = c(1, 6)) Asymptotic General Independence Test data: y by x T = -1, p-value = 0.3173 alternative hypothesis: two.sided > independence_test(y ~ x, data = mydf, subset = c(1, 2)) Asymptotic General Independence Test data: y by x T = NaN, p-value = NA alternative hypothesis: two.sided Warning message: The conditional covariance matrix has zero diagonal elements in: .local(.Object, ...) > try(independence_test(y ~ x, data = mydf, subset = 1)) Error in validObject(.Object) : invalid class "IndependenceProblem" object: FALSE > > ### names of expectation and covariance > YOY <- data.frame(length = c(46, 28, 46, 37, 32, 41, 42, 45, 38, 44, + 42, 60, 32, 42, 45, 58, 27, 51, 42, 52, + 38, 33, 26, 25, 28, 28, 26, 27, 27, 27, + 31, 30, 27, 29, 30, 25, 25, 24, 27, 30), + site = factor(c(rep("I", 10), rep("II", 10), + rep("III", 10), rep("IV", 10)))) > > it <- independence_test(length ~ site, data = YOY, + ytrafo = function(data) trafo(data, numeric_trafo = rank), + teststat = "quadtype") > expectation(it) I II III IV 205 205 205 205 > covariance(it) I II III IV I 1019.0385 -339.6795 -339.6795 -339.6795 II -339.6795 1019.0385 -339.6795 -339.6795 III -339.6795 -339.6795 1019.0385 -339.6795 IV -339.6795 -339.6795 -339.6795 1019.0385 > > mydf <- data.frame(x = rnorm(10), y = rnorm(10), z = gl(2, 5)) > it <- independence_test(x + y ~ z, data = mydf) > statistic(it, "linear") x y 1 -2.066068 0.3292961 > expectation(it) 1:x 1:y -1.6340021 -0.9750075 > covariance(it) 1:x 1:y 1:x 0.4417981 -0.8139286 1:y -0.8139286 2.5231787 >