Kruskal-Wallis test with details on pairwise comparisons

后端 未结 4 939
日久生厌
日久生厌 2020-12-12 23:11

The standard stats::kruskal.test module allows to calculate the kruskal-wallis test on a dataset:

>>> data(diamonds)
>>> kruskal.test(price         


        
相关标签:
4条回答
  • 2020-12-12 23:34

    One other approach besides kruskal::agricolae mentioned by Marek, is the Nemenyi-Damico-Wolfe-Dunn test implemented in the help page for oneway_test in the coin package that uses multcomp. Using hadley's setup and reducing the B= value for the approximate() function so it finishes in finite time:

    #updated translation of help page implementation of NDWD
    NDWD <- 
        independence_test(dv ~ iv, data = sum_codings1, distribution = approximate(B = 10000), 
                              ytrafo = function(data) trafo(data, numeric_trafo = rank_trafo), 
                              xtrafo = mcp_trafo(iv = "Tukey"))
    
    
        ### global p-value
        print(pvalue(NDWD))
    
        ### sites (I = II) != (III = IV) at alpha = 0.01 (page 244)
        print(pvalue(NDWD, method = "single-step"))
    

    More stable results on that larger dataset may require increasing the B value and increasing the user's patience.

    Jan: 2012: There was recently a posting on R-help claiming unexpected results from this method so I forwarded that email to the maintainer. Mark Difford said he had confirmed the problems and offered an alternate tests with the nparcomp package: https://stat.ethz.ch/pipermail/r-help/2012-January/300100.html

    There were also in the same week a couple of other suggestions on rhelp for post-hoc contrasts to KW tests: kruskalmc suggested by Mario Garrido Escudero and rms::polr followed by rms::contrasts suggested by Frank Harrell https://stat.ethz.ch/pipermail/r-help/2012-January/300329.html

    Nov 2015: Agree with toto_tico that help page code of coin package has been changed in the intervening years. The ?independence_test help page now offers a multivariate-KW test and the ?oneway_test help page has replace its earlier implementation with the code above usng the independence_test function.

    0 讨论(0)
  • 2020-12-12 23:37

    Unfortunately I don't know of a function like this. If there isn't one already, it would be an interesting task to construct a function that returns a matrix with all pairwise treatment comparisons. A contrast is considered significant if the following inequality is satisfied


    (source: statsdirect.com)

    where T is the Kruskal-Wallis test statistic for k samples, S^2 is the denominator of the T statistic, N is the total number (all ni) and Ri is the sum of the ranks (from all samples pooled) for the ith sample, and t is a quantile from the Student t distribution on N-k degrees of freedom.

    I know I didn't help much :)
    I am also waiting for a better answer

    0 讨论(0)
  • 2020-12-12 23:42

    You can use PMCMR package. There is more information about it.

    Spelling_Grades <- c(90,87,89,90,75,88,97,99,78,85,72,76,77,79,70)
    Methods <- c("A","A","A","A","B","B","B","B","B","B","C","C","C","C","C")
    kruskalmc(Spelling_Grades~Methods)
    
    #This method doesn't accept characters that's why I've changed the methods to integer
    Methods <- c(1,1,1,1,2,2,2,2,2,2,3,3,3,3,3)
    posthoc.kruskal.nemenyi.test(Spelling_Grades~Methods) 
    

    The two methods above give same results.

    0 讨论(0)
  • 2020-12-12 23:48

    I would have thought you'd be able to do the following:

    data(diamonds, package = "ggplot2")
    
    library(coin)
    library(multcomp)
    
    kt <- kruskal_test(price ~ clarity, data = diamonds)
    glht(kt, mcp(clarity = "Tukey"))
    

    But it seems like multcomp doesn't support coin objects (yet?).

    0 讨论(0)
提交回复
热议问题