wilcox.test
Wilcoxon Rank Sum and Signed Rank 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, ...)
## Default S3 method:
wilcox.test(x, y = NULL, alternative = c("two.sided", "less", "greater"),
    mu = 0, paired = FALSE, exact = NULL, correct = TRUE, conf.int = FALSE,
    conf.level = 0.95, ...)
## S3 method for class 'formula':
wilcox.test(formula, data, subset, na.action, ...)

Arguments

x a numeric vector that contains the sample values. Missing values (NAs) are ignored.
y a numeric vector that contains the second sample values. If y is specified, a two-sample test is performed. Missing values (NAs) are ignored. If you also specify paired = TRUE, then length(x) must equal length(y), and in the case where an observation pair (x[i], y[i]) has at least one NA value, that observation pair is removed.
alternative a character string that specifies the alternative hypothesis. Possible values are:
"two.sided" to specify that the locations of x and y are different.
"greater" to specify that the location of x is greater than that of y.
"less" to specify that the location of x is less than that of y.
Note: You only need to enter enough of the character string to create a unique match for the value.
mu a numeric value that represents the location shift for the distribution of x.
paired a logical value. If TRUE, the Wilcoxon signed rank test is computed. Default is the Wilcoxon rank sum test.
exact a logical value. If TRUE, the exact distribution for the test statistic is used to compute the p-value (if possible).
correct a logical value. If TRUE, a continuity correction is applied to the normal approximation for the p-value.
conf.int a logical value. If TRUE, the confidence interval and estimation are computed.
conf.level a numeric vector in the range [0, 1] that specifies the confidence level for the returned confidence interval.
formula a formula of the form v~g that gives the name of a numeric variable (v) and the name of a grouping factor (g). g must have exactly two levels and length equal to that of v.
data a data frame that contains the variables named in the formula and subset arguments. Defaults to the parent frame from which the function was called.
subset a vector that specifies which subset of the rows of the data should be used. This can be a logical vector that is replicated to have length equal to the number of rows of data, a numeric vector that indicates the row numbers to be included, or a character vector of the row names that should be included. By default, all rows are included.
na.action a function that handles missing values. See na.action for details.
... additional arguments.

Details

Value
a list of class htest that represents the result of the Wilcoxon rank sum or Wilcoxon signed rank test and contains the following components:
statistic test statistic with a names attribute that lists the statistic:
"V" Wilcoxon signed rank test
"M" Wilcoxon rank sum test
parameters always NULL (in this version).
p.value p-value for the test.
null.value value of the location values or difference in locations specified by the null hypothesis. The value for null.value is equal to the value of the input argument mu with names attribute "location shift" when paired = TRUE or attribute "location" when paired = FALSE.
alternative a character string that returns the alternative hypothesis ("two.sided", "greater", or "less") as specified in the alternative argument.
method a character string for the name of the method used for the calculation.
data.name a character string (vector of length 1) that contains the names of the x and y input vectors.
conf.int confidence interval for the test with attribute conf.level. Only returned when you set conf.int = TRUE.
estimate estimation of test if conf.int = TRUE.
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.
David F. Bauer (1972), Constructing confidence sets using rank statistics. Journal of the American Statistical Association 67, 687--690.
See Also
Wilcoxon, t.test.
Examples
x <- c(8.2, 9.4, 9.6, 9.7, 10.0, 14.5, 15.2, 16.1, 17.6, 21.5)
y <- c(4.2, 5.2, 5.8, 6.4, 7.0, 7.3, 10.1, 11.2, 11.3, 11.5)

# A Wilcoxon rank sum test: wilcox.test(x, y) wilcox.test(x, y, alternative = "less", exact = FALSE, correct = FALSE, conf.int = TRUE, conf.level = 0.9)

# A Wilcoxon signed rank test: wilcox.test(x) wilcox.test(x, y, paired = TRUE) wilcox.test(x, y, alternative = "greater", exact = FALSE, mu = 0.01, paired = TRUE, correct = FALSE, conf.int = TRUE)

# Formula interface wilcox.test(Weight ~ I(Country == "USA"), data=Sdatasets::car.all)

Package stats version 6.0.0-69
Package Index