[banner]

Summary and Analysis of Extension Program Evaluation in R

Salvatore S. Mangiafico

Brunner–Munzel, Stratified Wilcoxon–Mann–Whitney, and Stratified Kruskal–Wallis Tests

Brunner–Munzel test

 

The Brunner–Munzel test is used to test the stochastic equality of two independent samples, similar to the Wilcoxon–Mann–Whitney test.  The Brunner–Munzel test is sometimes called the generalized Wilcoxon test.

 

The brunnermunzel.test function in the brunnermunzel package can be used for this test.  There is also an option to conduct the test by permutation.

 

van Elteren test

 

The van Elteren test is a stratified version of the Wilcoxon–Mann–Whitney test.  That is, it compares two groups across another variable representing strata.

 

The sanon package conducts a stratified Wilcoxon–Mann–Whitney test.  It can also handle models with multiple stratifying variables.

 

A stratified test can also be conducted with the coin package.

 

Another approach is to use aligned ranks transformation anova.

 

Note that all these approaches are slightly different and return different results.

 

Stratified Kruskal–Wallis test

 

A stratified Kruskal–Wallis test can be used to compare multiple groups across another stratifying variable.   This test can be conducted with the free1way function or with the kruskal_test function in the coin package.

 

 

Packages used in this chapter

 

The packages used in this chapter include:

•  brunnermunzel

•  rcompanion

•  sanon

•  coin

•  ARTool

 

The following commands will install these packages if they are not already installed:


if(!require(brunnermunzel)){install.packages("brunnermunzel")}
if(!require(rcompanion)){install.packages("rcompanion")}
if(!require(sanon)){install.packages("sanon")}
if(!require(coin)){install.packages("coin")}
if(!require(ARTool)){install.packages("ARTool")}

 

Brunner–Munzel test example


Data = read.table(header=TRUE, stringsAsFactors=TRUE, text="

 Speaker  Likert
 Pooh      3
 Pooh      5
 Pooh      4
 Pooh      4
 Pooh      4
 Pooh      4
 Pooh      4
 Pooh      4
 Pooh      5
 Pooh      5
 Piglet    2
 Piglet    4
 Piglet    2
 Piglet    2
 Piglet    1
 Piglet    2
 Piglet    3
 Piglet    2
 Piglet    2
 Piglet    3
")


Brunner Munzel test

 

Note that the results also give the Vargha and Delaney A statistic and confidence interval for this statistic.


library(brunnermunzel)

brunnermunzel.test(Likert ~ Speaker, data=Data)


Brunner-Munzel Test

Brunner-Munzel Test Statistic = 10.354, df = 12.688, p-value = 1.495e-07

95 percent confidence interval:
 0.8558721 1.0441279

sample estimates:
P(X<Y)+.5*P(X=Y)
            0.95


Brunner Munzel test by permutation


library(brunnermunzel)

brunnermunzel.test(Likert ~ Speaker, data=Data, perm=TRUE)


permuted Brunner-Munzel Test

p-value = 0.0002382

sample estimates:
P(X<Y)+.5*P(X=Y)
            0.95


Comparison to the Wilcoxon–Mann–Whitney test


wilcox.test(Likert ~ Speaker, data=Data, correct=FALSE)


Wilcoxon rank sum test

W = 5, p-value = 0.0004065


Vargha and Delaney’s A


library(rcompanion)

1 - vda(Likert ~ Speaker, data=Data, ci=TRUE)


   VDA lower.ci upper.ci
1 0.95        1    0.843

### Note these values essentially match the values given by

###  the brunnermunzel output, with some variability in the

###  confidence interval for bootstrapping, and the fact that

###  the brunnermunzel output allows for values to exceed 1.


Stratified Wilcoxon–Mann–Whitney example


Data1 = read.table(header=TRUE, stringsAsFactors=TRUE, text="

Instructor        Supplement  Sodium
'Brendon Small'   A           1200
'Brendon Small'   A           1400
'Brendon Small'   A           1350
'Brendon Small'   A            950
'Brendon Small'   A           1400
'Brendon Small'   B           1150
'Brendon Small'   B           1300
'Brendon Small'   B           1325
'Brendon Small'   B           1425
'Brendon Small'   B           1500
'Brendon Small'   C           1250
'Brendon Small'   C           1150
'Brendon Small'   C            950
'Brendon Small'   C           1150
'Brendon Small'   C           1600
'Brendon Small'   D           1300
'Brendon Small'   D           1050
'Brendon Small'   D           1300
'Brendon Small'   D           1700
'Brendon Small'   D           1300
'Melissa Robins'  A            900
'Melissa Robins'  A           1100
'Melissa Robins'  A           1150
'Melissa Robins'  A            950
'Melissa Robins'  A           1100
'Melissa Robins'  B           1150
'Melissa Robins'  B           1250
'Melissa Robins'  B           1250
'Melissa Robins'  B           1225
'Melissa Robins'  B           1325
'Melissa Robins'  C           1125
'Melissa Robins'  C           1025
'Melissa Robins'  C            950
'Melissa Robins'  C            925
'Melissa Robins'  C           1200
'Melissa Robins'  D           1100
'Melissa Robins'  D            950
'Melissa Robins'  D           1300
'Melissa Robins'  D           1400
'Melissa Robins'  D           1100
")

xtabs(~ Instructor + Supplement, data=Data1)


                Supplement
Instructor       A B C D
  Brendon Small  5 5 5 5
  Melissa Robins 5 5 5 5

### Counts of observations per Instructor and Supplement


sanon package


library(sanon)

Out = sanon(Sodium ~ grp(Instructor) + strt(Supplement), data=Data1)

summary(Out)


       Estimate Std.Err Chisq Pr(>Chisq)  
Sodium  -0.2650  0.0809  10.7     0.0011 **


Out


Sample size: 40

Strata ( Supplement ): A, B, C, D

Response levels:
[Sodium; 19 levels] (lower) 900, 925, 950, ..., 1500, 1600, 1700 (higher)

Design Matrix:
       [,1]
Sodium    1


coin package

 

library(coin)

wilcox_test(Sodium ~ Instructor | Supplement, data=Data1)


Asymptotic Wilcoxon-Mann-Whitney Test

Instructor (Brendon Small, Melissa Robins)
stratified by Supplement

Z = 2.9858, p-value = 0.002829


free1way function


free1way(Sodium ~ Instructor | Supplement, data=Data1)


Stratified 2-sample Wilcoxon test against proportional
 odds alternatives

Perm Z = -2.8086, p-value = 0.004976


Comparison to unstratified Wilcoxon-Mann-Whitney


wilcox_test(Sodium ~ Instructor, data=Data1)


Asymptotic Wilcoxon-Mann-Whitney Test

Z = 2.851, p-value = 0.004359


Aligned ranks transformation anova


library(ARTool)

model = art(Sodium ~ Instructor + Supplement + Instructor:Supplement, data=Data1)

anova(model)


Analysis of Variance of Aligned Rank Transformed Data

                        Df Df.res F value    Pr(>F)  
1 Instructor             1     32 9.74449 0.0037985 **
2 Supplement             3     32 2.55669 0.0725482  .
3 Instructor:Supplement  3     32 0.44091 0.7253272  


Stratified Kruskal–Wallis example


Data2 = read.table(header=TRUE, stringsAsFactors=TRUE, text="

Instructor        Town             Sodium
'Brendon Small'   Squiggleville    1200
'Brendon Small'   Squiggleville    1400
'Brendon Small'   Squiggleville    1350
'Brendon Small'   Metalocalypse     950
'Brendon Small'   Squiggleville    1400
'Brendon Small'   Squiggleville    1150
'Brendon Small'   Squiggleville    1300
'Brendon Small'   Metalocalypse    1325
'Brendon Small'   Metalocalypse    1425
'Brendon Small'   Squiggleville    1500
'Brendon Small'   Squiggleville    1250
'Brendon Small'   Metalocalypse    1150
'Brendon Small'   Metalocalypse     950
'Brendon Small'   Squiggleville    1150
'Brendon Small'   Metalocalypse    1600
'Brendon Small'   Metalocalypse    1300
'Brendon Small'   Metalocalypse    1050
'Brendon Small'   Metalocalypse    1300
'Brendon Small'   Squiggleville    1700
'Brendon Small'   Squiggleville    1300
'Coach McGuirk'   Squiggleville    1100
'Coach McGuirk'   Squiggleville    1200
'Coach McGuirk'   Squiggleville    1250
'Coach McGuirk'   Metalocalypse    1050
'Coach McGuirk'   Metalocalypse    1200
'Coach McGuirk'   Metalocalypse    1250
'Coach McGuirk'   Squiggleville    1350
'Coach McGuirk'   Squiggleville    1350
'Coach McGuirk'   Squiggleville    1325
'Coach McGuirk'   Squiggleville    1525
'Coach McGuirk'   Squiggleville    1225
'Coach McGuirk'   Squiggleville    1125
'Coach McGuirk'   Metalocalypse    1000
'Coach McGuirk'   Metalocalypse    1125
'Coach McGuirk'   Squiggleville    1400
'Coach McGuirk'   Metalocalypse    1200
'Coach McGuirk'   Squiggleville    1150
'Coach McGuirk'   Squiggleville    1400
'Coach McGuirk'   Squiggleville    1500
'Coach McGuirk'   Squiggleville    1200
'Melissa Robins'  Metalocalypse     900
'Melissa Robins'  Metalocalypse    1100
'Melissa Robins'  Metalocalypse    1150
'Melissa Robins'  Metalocalypse     950
'Melissa Robins'  Metalocalypse    1100
'Melissa Robins'  Metalocalypse    1150
'Melissa Robins'  Squiggleville    1250
'Melissa Robins'  Squiggleville    1250
'Melissa Robins'  Squiggleville    1225
'Melissa Robins'  Squiggleville    1325
'Melissa Robins'  Metalocalypse    1125

'Melissa Robins'  Metalocalypse    1025
'Melissa Robins'  Metalocalypse     950
'Melissa Robins'  Metalocalypse     925
'Melissa Robins'  Squiggleville    1200
'Melissa Robins'  Metalocalypse    1100
'Melissa Robins'  Metalocalypse     950
'Melissa Robins'  Metalocalypse    1300
'Melissa Robins'  Squiggleville    1400
'Melissa Robins'  Metalocalypse    1100
")


###  Order factors by the order in data frame
###  Otherwise, R will alphabetize them

Data2$Instructor = factor(Data2$Instructor,
                         levels=unique(Data2$Instructor))

Data2$Town       = factor(Data2$Town,
                         levels=unique(Data2$Town))


coin package


library(coin)

kruskal_test(Sodium ~ Instructor | Town, data=Data2)


Asymptotic Kruskal-Wallis Test

chi-squared = 6.2652, df = 2, p-value = 0.04361


free1way function


free1way(Sodium ~ Instructor | Town, data=Data2)


Stratified 3-sample Kruskal-Wallis test against
 proportional odds alternatives

Perm chi-squared = 4.4812, df = 2, p-value = 0.1064


Aligned ranks transformation anova


library(ARTool)

model = art(Sodium ~ Instructor + Town + Instructor:Town, data=Data2)

anova(model)

 

Analysis of Variance of Aligned Rank Transformed Data

                  Df Df.res  F value     Pr(>F)   
1 Instructor       2     54  6.05487   0.004241  **
2 Town             1     54 22.55388 1.5476e-05 ***
3 Instructor:Town  2     54  0.59009   0.557809   


Compare to unstratified Kruskal–Wallis


kruskal_test(Sodium ~ Instructor, data=Data2)


Asymptotic Kruskal-Wallis Test

chi-squared = 9.6704, df = 2, p-value = 0.007945


References

 

Kawaguchi, A, and Koch, G.G. 2015. sanon: An R Package for Stratified Analysis with Nonparametric Covariable Adjustment. JSS Journal of Statistical Software: 67(9). doi: 10.18637/jss.v067.