[R] post hoc kruskal wallis

Torsten Hothorn Torsten.Hothorn at rzmail.uni-erlangen.de
Fri Jun 3 11:14:00 CEST 2005


On Thu, 2 Jun 2005, Liaw, Andy wrote:

> By post hoc I guess you meant pairwise comparisons.  You might want to check
> out the npmc package on CRAN.
>

?oneway_test in `coin' has an example, essentially

### Length of YOY Gizzard Shad from Kokosing Lake, Ohio,
### sampled in Summer 1984, Hollander & Wolfe (1999), Table 6.3, page 200
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))))

### Kruskal-Wallis test, approximate exact p-value
kw <- kruskal_test(length ~ site, data = YOY,
             distribution = approximate(B = 9999))
kw
pvalue(kw)

### Nemenyi-Damico-Wolfe-Dunn test (joint ranking)
### Hollander & Wolfe (1999), page 244
### (where Steel-Dwass results are given)
if (require(multcomp)) {

    NDWD <- oneway_test(length ~ site, data = YOY,
        ytrafo = function(data) trafo(data, numeric_trafo = rank),
        xtrafo = function(data) trafo(data, factor_trafo = function(x)
            model.matrix(~x - 1) %*% t(contrMat(table(x), "Tukey"))),
        teststat = "maxtype", distribution = approximate(B = 90000))

    ### global p-value
    print(pvalue(NDWD))

    ### sites (I = II) != (III = IV) at alpha = 0.01 (page 244)
    print(pvalue(NDWD, adjusted = TRUE))
}


the key step is

xtrafo = function(data) trafo(data, factor_trafo = function(x)
            model.matrix(~x - 1) %*% t(contrMat(table(x), "Tukey")))

where you may specify _any_ contrast matrix, for example just a subset of
all pairwise comparisons you are willing to pay for.

Torsten

> Andy
>
> > From: amberfer at ull.es
> >
> > I´m looking for a program with a post hoc kruskall Wallis
> > test like the Tukey-
> > type non parametric test of ZAR(Biostatistical Analysis
> > 2ºEdition). SSPS
> > hasn´t got any non parametric post host test. I don´t know if
> > R has an
> > appropiate post hoc non parametric test. I´m not sure if NDWD
> > test of the
> > package "coin" is an appropiate test or if the package "npmc"
> > is a best option.
> > Thank you
> >
> >
> > Alfredo Bermúdez
> >
> >
> >
> >
> >
> >
> >
> > -------------------------------------------------
> >
> >
> > ----- Fin del mensaje reenviado -----
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>




More information about the R-help mailing list