Wilcoxon Rank Sum and Signed Rank Sum Tests

DESCRIPTION:
Computes Wilcoxon rank sum test for two sample data (equivalent to the Mann-Whitney test) or the Wilcoxon signed rank test for paired or one sample data.

USAGE:
wilcox.test(x, y, alternative="two.sided", mu=0, paired=F, exact=T,
            correct=T)

REQUIRED ARGUMENTS:
x:
numeric vector. Missing values (NAs) are allowed but ignored at calculation.

OPTIONAL ARGUMENTS:
y:
numeric vector. If supplied a two sample test is performed. If paired=TRUE then x and y must have the same length. Missing values (NAs) are allowed but ignored at calculation.
alternative:
a character string specifying the alternative hypothesis, "greater" (the location of x is greater than that of y) or "less" (the location of x is less than that of y) or "two.sided" (the locations of x and y are different). Only enough of the string to determine a unique match is required.
mu:
the location shift for the distribution of x.
paired:
if TRUE, the Wilcoxon signed rank test is computed. The default is the Wilcoxon rank sum test.
exact:
if TRUE the exact distribution for the test statistic is used to compute the p-value if possible.
correct:
if TRUE a continuity correction is applied to the normal approximation for the p-value.

VALUE:
a list with class attribute "htest", representing the result of the Wilcoxon rank sum or Wilcoxon signed rank test:
statistic:
the test statistic with a name describing the statistic.
parameters:
the parameters for the test statistic with names attribute "n" (number of meaningful observations in x) for the exact Wilcoxon signed rank statistic or "n" and "m" (number of meaningful observations in x and y, respectively) for the exact Wilcoxon rank sum test. This component is missing if a normal approximation is use for the test.
p.value:
the p-value for the test.
null.value:
the value of the location values or difference in locations specified by the null hypothesis. This equals the input argument mu with names attribute "mu".
alternative:
the input argument alternative.
method:
the name of the test applied.
data.name:
a character string describing the actual data names used for the test.

NULL:
For the Wilcocon rank sum test, the null hypothesis is that the locations of the distributions of x and y differ by mu.

For the one-sample Wilcoxon signed rank test, the null hypothesis is that the median of the distribution of x (if only x is supplied) is mu. For the two-sample paired case, where both x and y are provided (and paired is TRUE), the null hypothesis is that the median of the distribution of x - y is mu.


ASSUMPTIONS:
For the Wilcoxon rank sum test, the x and y vectors are independent samples from their respective distributions, and there is mutual independence between the two sample.

For the Wilcoxon signed rank test the values of x or x - y are independent observations from the same symmetric distribution.


DETAILS:
The Wilcoxon rank sum test statistic, W, is defined as sum(rank(c(x-mu,y))[seq(along=x)]) To compute probabilities for large datasets, a normal approximation is used for the distribution of the test statistic when the length of x or y is greater than 49 (or when exact=F). See the hard copy help file for the Normal approximation used for W when the length of x or y is greater than 49. If there are ties in the vector c(x-mu,y) an exact p-value for the test cannot be computed. In this case, the normal approximation given by Lehmann (1975, p. 20) is used.

The Wilcoxon signed-rank test statistic, V, is the rank sum of those abs(x - mu - y) with x - mu - y > 0. For n = length(x) greater than 25, a normal approximation is used to compute the probability (or if exact=F). See the hard copy help file for the Normal approximation used for the test statistic. If there are ties in the absolute values of the differences, x - mu - y, an exact probability for the test cannot be computed. The normal approximation given by Lehmann (1975, p. 130) is used in this case.


REFERENCES:
Conover, W. J. (1980). Practical Nonparametric Statistics, 2nd ed. Wiley, New York.

Lehmann, E. L. (1975). Nonparametrics: Statistical Methods Based on Ranks. Holden and Day, San Francisco.


SEE ALSO:
Wilcoxon , t.test .

EXAMPLES:
# A Wilcoxon rank sum test
wilcox.test(x, y)
# A Wilcoxon signed rank sum test
wilcox.test(x, y, paired=T)