'plot.mw': R function for visually displaying MannWhitney test's results (DOI: 10.13140/RG.2.1.4630.7601)
'plot.mw' is an R function which allows to perform MannWhitney test, and to display the test's results in a plot along with two boxplots. For information about the test, and on what it is actually testing, see for instance the interesting article by R M Conroy, What hypotheses do "nonparametric" twogroup tests actually test?, in The Stata Journal 12 (2012): 19. A sample dataset (in .txt format) can be downloaded HERE. The dataset contains some measurements in the first column, and a grouping variable in the second one. This is the format in which data must be fed into the function.
The function is quite straightforward:
plot.mw(data, notch, omm, HL)
where:
data is the dataframe containing the data (arranged according to what has been described just few lines above);
notch is a logical value which takes FALSE (by default) or TRUE if user does not or do want to have notched boxplots in the final display, respectively; it is worth noting that overlapping of notches indicates a not significant difference at about 95% confidence (see McGill R, Tukey JW, Larsen WA, Variations of Box Plots, in The American Statistician 32 (1978): 12–16);
omm (which stands for overall mean and median) takes FALSE (by default) or TRUE if user wants the mean and median of the overall sample plotted in the chart (as a dashed RED line and dotted BLUE line respectively);
HL is a logical value that takes TRUE or FALSE (default) if the user wants to diplay the distribution of the pairwise differences between the values of the two samples being compared; the median of that distribution is the HodgesLehmann estimator.
With reference to the illustrative dataset cited above, the function allows to get the plots below:
The function is quite straightforward:
plot.mw(data, notch, omm, HL)
where:
data is the dataframe containing the data (arranged according to what has been described just few lines above);
notch is a logical value which takes FALSE (by default) or TRUE if user does not or do want to have notched boxplots in the final display, respectively; it is worth noting that overlapping of notches indicates a not significant difference at about 95% confidence (see McGill R, Tukey JW, Larsen WA, Variations of Box Plots, in The American Statistician 32 (1978): 12–16);
omm (which stands for overall mean and median) takes FALSE (by default) or TRUE if user wants the mean and median of the overall sample plotted in the chart (as a dashed RED line and dotted BLUE line respectively);
HL is a logical value that takes TRUE or FALSE (default) if the user wants to diplay the distribution of the pairwise differences between the values of the two samples being compared; the median of that distribution is the HodgesLehmann estimator.
With reference to the illustrative dataset cited above, the function allows to get the plots below:
The boxplots display the distribution of the values of the two samples (here labelled a and b), and jittered points represent the individual observations. At the bottom of the chart, a subtitle arranged on three lines reports relevant statistics:
test statistic (namely, U) and the associated z and p value;
Probability of Superiority value (which can be interpreted as an effectsize measure, as discussed HERE); in this case, as reported in the second line of the subtitle, the probability of observing a number (randomly drawn) from sample a being larger than a (randomly drawn) number from sample b is 0.92;
another measure of effect size, namely r (see HERE), whose thresholds are indicated in the last line of the plot's subtitle.
The density plot (coupled with a rug plot at the botton of the same chart) displays the distribution of the pairwise differences between the values of the two samples being compared. The median of this distribution (which is represented by a blue reference line in the same chart) corresponds to the HodgesLehmann estimator.
Please note that, in order for the function to work, two packages must be already installed in R: 'plyr' and 'coin'.
test statistic (namely, U) and the associated z and p value;
Probability of Superiority value (which can be interpreted as an effectsize measure, as discussed HERE); in this case, as reported in the second line of the subtitle, the probability of observing a number (randomly drawn) from sample a being larger than a (randomly drawn) number from sample b is 0.92;
another measure of effect size, namely r (see HERE), whose thresholds are indicated in the last line of the plot's subtitle.
The density plot (coupled with a rug plot at the botton of the same chart) displays the distribution of the pairwise differences between the values of the two samples being compared. The median of this distribution (which is represented by a blue reference line in the same chart) corresponds to the HodgesLehmann estimator.
Please note that, in order for the function to work, two packages must be already installed in R: 'plyr' and 'coin'.
You can get the function via a small donation (about a couple of USD) >


Upon making your donation, please do not forget to provide your preferred email contact where you will receive the file.
Have you found this website helpful? Consider to leave a comment in this page.