Skip to content
Prev 76374 / 398502 Next

stratified Wilcoxon available?

On Mon, 29 Aug 2005, Peter Dalgaard wrote:

            
the conditional version of the above test can be computed as follows:

R> library("coin")
R> set.seed(290875)
R> mydf <- data.frame(y = rnorm(90), x = gl(3, 30)[sample(1:90)], b = gl(3, 30))
R>
R> ### with global ranks, i.e., ranking without using the blocks
R> kruskal_test(y ~ x | b, data = mydf)

        Asymptotic Kruskal-Wallis Test

data:  y by groups 1, 2, 3
         stratified by b
T = 0.5242, df = 2, p-value = 0.7694

R>
R> ### with _blockwise_ ranking and quadratic form of the test statistic
R> independence_test(y ~ x | b, data = mydf, ytrafo = function(data) trafo(data,
+                   numeric_trafo = rank, block = mydf$b), teststat = "quad")

        Asymptotic General Independence Test

data:  y by groups 1, 2, 3
         stratified by b
T = 0.3824, df = 2, p-value = 0.826

R>
R> ### the same
R> SKruskal.test(y ~ x | b, data = mydf)

        Kruskal-Wallis stratified rank sum test

data:  y , group:  x , strata:  b
K = 0.3824, df = 2, p-value = 0.826

R>
R>
R>
R> ### trend test (using scores 1, 2, 3)
R> independence_test(y ~ x | b, data = mydf, ytrafo = function(data) trafo(data,
+                   numeric_trafo = rank, block = mydf$b), teststat = "quad",
+                   scores = list(x = 1:3))

        Asymptotic General Independence Test

data:  y by groups 1 < 2 < 3
         stratified by b
T = 0.0264, df = 1, p-value = 0.871

R>
R> ### hm.
R> SKruskal.test(y ~ x | b, data = mydf, trend = TRUE)
Error in SKruskal.test(y ~ x | b, data = mydf, trend = TRUE) :
        subscript out of bounds

Best,

Torsten