https://github.com/cran/coin
Raw File
Tip revision: d0e2eaf5ae231191c0d6278ad7b87d4e0dc855f9 authored by Torsten Hothorn on 03 November 2006, 00:00:00 UTC
version 0.5-2
Tip revision: d0e2eaf
regtest_Ksample.Rout.save

R version 2.5.0 Under development (unstable) (2006-11-01 r39765)
Copyright (C) 2006 The R Foundation for Statistical Computing
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 an HTML browser interface to help.
Type 'q()' to quit R.

> 
> ### Regression tests for the K sample problem, i.e.,
> ### testing the independence of a numeric variable
> ### `y' and a factor `x' (possibly blocked)
> 
> set.seed(290875)
> library(coin)
Loading required package: survival
Loading required package: splines
Loading required package: mvtnorm
Loading required package: modeltools
> isequal <- coin:::isequal
> 
> ### generate data
> dat <- data.frame(x = gl(4, 25), y = rnorm(100), block = gl(5, 20))[sample(1:100, 50),]
> 
> ### Kruskal-Wallis Test
> 
> ### asymptotic distribution
> ptwo <- kruskal.test(y ~ x, data = dat)$p.value
> 
> stopifnot(isequal(pvalue(kruskal_test(y ~ x, data = dat)), ptwo))
> 
> stopifnot(isequal(pvalue(oneway_test(y ~ x, data = dat, distribution = "asympt", 
+                                    teststat = "quad",
+     ytrafo = function(data) trafo(data, numeric_trafo = rank))), ptwo))
> 
> ### approximated distribution
> rtwo <- pvalue(kruskal_test(y ~ x, data = dat, distribution = "approx")) / ptwo
> stopifnot(all(rtwo > 0.9 & 
+               rtwo < 1.1))
> 
> ### <FIXME> add block examples </FIXME>
> 
> ### sanity checks
> try(kruskal_test(x ~ y, data = dat))
Error in check(itp) : ‘object’ does not represent a K sample problem
> try(kruskal_test(x ~ y | y, data = dat))
Error in .local(.Object, ...) : ‘block’ is not a factor
> 
> ### Fligner Test 
> 
> ### asymptotic distribution
> ptwo <- fligner.test(y ~ x, data = dat)$p.value                       
> 
> stopifnot(isequal(pvalue(fligner_test(y ~ x, data = dat)), ptwo))
> 
> dat$yy <- dat$y - tapply(dat$y, dat$x, median)[dat$x]
> stopifnot(isequal(pvalue(oneway_test(yy ~ x, data = dat, distribution = "asympt", 
+                                    teststat = "quad",
+     ytrafo = function(data) trafo(data, numeric_trafo = fligner_trafo))), ptwo))
> 
> ### approximated distribution
> rtwo <- pvalue(fligner_test(y ~ x, data = dat, distribution = "approx")) / ptwo
> stopifnot(all(rtwo > 0.9 &                     
+               rtwo < 1.1))                     
> 
> ### <FIXME> add block examples </FIXME>
> 
> ### sanity checks
> try(fligner_test(x ~ y, data = dat)) 
Error in median.default(X[[1]], ...) : need numeric data
> try(fligner_test(x ~ y | y, data = dat))
Error in .local(.Object, ...) : ‘block’ is not a factor
> 
> 
back to top