[R] Jonckheere-Terpstra test using coin package?

Dale Steele dale.w.steele at gmail.com
Wed May 5 22:09:33 CEST 2010


Using coin ... answer provided by Prof. Hothorn.

control <- c(40, 35, 38, 43, 44, 41)
rough <- c(38, 40, 47, 44, 40, 42)
accurate <- c(48, 40, 45, 43, 46, 44)

pieces <- list(control, rough, accurate)
n <- c(6, 6, 6)
grp <- as.ordered(factor(rep(1:length(n),n)))

library("coin")
library("multcomp")

(y <- unlist(pieces))
k <- length(pieces)
(x <- as.ordered(factor(rep(1:k,n))))


 ### look at K. The second line just sums up.
       ff <- function(x) {
           K <- contrMat(table(x), "Tukey")[,x]
           as.vector(rep(1, nrow(K)) %*%K)
       }

independence_test(y ~ x, ytrafo = rank,
                  xtrafo = function(data) trafo(data, factor_trafo = ff),
                  alternative="greater",
                  distribution="asymptotic")

independence_test(y ~ x, ytrafo = rank,
                  xtrafo = function(data) trafo(data, factor_trafo = ff),
                  alternative="greater",
                  distribution=approximate(B=500000))

On Wed, Apr 21, 2010 at 8:23 PM, Dale Steele <dale.w.steele at gmail.com> wrote:
> Is it possible to implement the Jonckheere-Terpstra test for ordered
> alternatives using the coin package: Conditional Inference Procedures
> in a Permutation Test Framework?
>
> I found jonckheere.test{clinfun}, but it uses a normal approximation
> when ties are present in the data.  To make this concrete, I've
> include
> a small dataset.  Thanks.  --Dale
>
> Hollander and Wolfe, 1999 Table 6.6, pg 205
>
> control <- c(40, 35, 38, 43, 44, 41)
> rough <- c(38, 40, 47, 44, 40, 42)
> accurate <- c(48, 40, 45, 43, 46, 44)
>
> pieces <- list(control, rough, accurate)
> n <- c(6, 6, 6)
> grp <- as.ordered(factor(rep(1:length(n),n)))
>
> library(clinfun)
> jonckheere.test(unlist(pieces), grp, alternative="increasing")
>
>
> Output below ...
>> jonckheere.test(unlist(pieces), grp, alternative="increasing")
>
>        Jonckheere-Terpstra test
>
> data:
> JT = 79, p-value = 0.02163
> alternative hypothesis: increasing
>
> Warning message:
> In jonckheere.test(unlist(pieces), grp, alternative = "increasing") :
>  TIES: p-value based on normal approximation
>



More information about the R-help mailing list