Skip to main content
Statistics LibreTexts

15.2: Wilcoxon rank sum test

  • Page ID
    45237
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    Introduction

    Wilcoxon rank sum test, also called the two-sample Wilcoxon test, is a nonparametric test. It is equivalent to another nonparametric test called the Mann-Whitney test, which was independently derived. We get the Wilcoxon test statistic in Rcmdr through the Statistics submenu.

    Rcmdr: Statistics → Nonparametric tests → Two-sample Wilcoxon Test

    I’ll show you the test with an example. We’ll use the same data set introduced in chapter 10.3, body mass (g) for four geckos (Hemidactylus frenatus, Fig. \(\PageIndex{1}\)) and four green anolis lizards (Anolis carolinensis, Fig. \(\PageIndex{2}\)).

    Female common house gecko, climbing on a wall.
    Figure \(\PageIndex{1}\): Female common house gecko, Hemidactylus frenatus, central Oahu, M. Dohm 2018.
    Male green anolis lizard, resting on a metal fence rail.
    Figure \(\PageIndex{2}\): Male Anolis carolinensis, ‘Akaka Falls, Hawai`i, M. Dohm 2018.

    Wilcoxon test, worked example

    Geckos: 3.186, 2.427, 4.031, 1.995
    Anoles: 5.515, 5.659, 6.739, 3.184
    Note:

    This test in Rcmdr requires that data are in a stacked worksheet and not in unstacked worksheet with two columns. If you need help with worksheet format, then see Part07 in Mike’s Workbook for Biostatistics.

    We choose from the Rcmdr Nonparametric statistics menu the Two-sample Wilcoxon test (Fig. \(\PageIndex{3}\)), then a two-tailed test of the null hypothesis (Fig. \(\PageIndex{4}\)) and elect to use the defaults for the tests and calculations of P-values.

    Popup menu for Two-Sample Wilcoxon Test in R Commander, showing the Data tab. The selected variable for Groups is lizard, and the selected Response Variable is mass.
    Figure \(\PageIndex{3}\): Screenshot Rcmdr menu 2 sample Wilcoxon test. Options are selected by clicking on “Options” tab (see Fig. \(\PageIndex{4}\))
    Popup menu for Two-Sample Wilcoxon Test in R Commander, showing the Options tab. The difference is anoles minus geckos, the alternative hypothesis has the "two-sided" option selected, and the type of test has "default" selected.
    Figure \(\PageIndex{4}\): Screenshot of options tab Rcmdr menu 2 sample Wilcoxon test. Keep defaults to run the “Wilcoxon test.”

    Don’t forget to stack the data. Rcmdr won’t produce an error message if the data set is in the unstacked, improper conformation. Instead, Rcmdr menu options will not be available. For example, Fig. \(\PageIndex{5}\) shows a Two-sample Wilcoxon test… dimmed from view, not available for selection.

    Statistics dropdown menu open in R Commander. The Nonparametric test submenu is opened, showing that the option for Two-sample Wilcoxon test is grayed out.
    Figure \(\PageIndex{5}\): Screenshot of Rcmdr menu. Note Two-sample Wilcoxon test… is not available.

    The results of the test, copied from the Output window, are shown below.

    wilcox.test(Mass ~ Lizard, alternative="two.sided", data=LizardStacked)
    
    Wilcoxon rank sum test
    data: Mass by Lizard
    W = 14, p-value = 0.1143
    alternative hypothesis: true location shift is not equal to 0
    

    The calculation of the Wilcoxon test statistic (W) is straightforward, involving summing the ranks. Obtaining the p-value of the test of the null is a bit more involved as it depends on permutations of all possible combinations of differences. For us, R will do nicely with the details, and we just need to check the p-value.

    Here, we see that the medians are 5.6 g for the Anolis, and 2.8 g for the geckos. The associated p-value is 0.1143. Thus, we fail to reject the null hypothesis and conclude that there was no difference in median body mass. Note that this is the same general conclusion we got when we ran a independent \(t\)-test on this data set: there is no difference between day one and day two.


    Questions

    1. Conduct an independent \(t\)-test on the Lizard body mass data.
      • Make a box plot to display the two groups and describe the middle and variability.
      • Compare results of test of hypothesis. do they agree with the Wilcoxon test? If not, list possible reasons why the two tests disagree.
    2. Using the dataset below, test null hypothesis using independent \(t\)-test, Welch’s test, and nonparametric Wilcoxon’s test.
      • Make a box plot to display the two groups and describe the middle and variability.
      • Compare results of test of hypothesis. do they agree with the Wilcoxon test? If not, list possible reasons why the tests disagree.

    Data set

    var1 var2
    5.84 5.93
    5.72 5.95
    5.75 6.02
    5.78 5.81
    5.81 6.16
    5.81 5.95
    5.73 6.09
    5.77 5.89
    5.76 5.99
    5.86 5.60
    5.84 6.16
    5.83 6.16
    5.80 6.06
    5.78 6.07
    5.89 5.66
    5.83 6.14
    5.79 5.99
    5.84 6.15
    5.90 5.81
    5.86 6.20

    This page titled 15.2: Wilcoxon rank sum test is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Michael R Dohm via source content that was edited to the style and standards of the LibreTexts platform.

    • Was this article helpful?