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, ...)
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:
| ||||||
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. |
sum(rank(c(x-mu,y))[seq(along=x)]) - length(x)*(length(x)+1)/2 |
An exact p-value cannot be computed if the vector c(x - mu,y) contains ties. In this case, the normal approximation is calculated using Lehmann (1975, p. 20).
The null hypothesis is that the locations of the distributions of x and y differ by mu.
The function assumes that the vectors for x and y are independent samples from their respective distributions and there is mutual independence between the two samples.
rank sum of those abs(x - mu - y) where x - mu - y > 0 |
If argument conf.int = TRUE, a confidence interval and estimate for the pseudomedian (one-sample case) or for the difference of the location parameters x - y is computed. If exact p-values are available, an exact confidence interval is computed by the algorithm described in Bauer (1972), with the Hodges-Lehmann estimation. Otherwise, confidence interval and estimate are computed on normal approximations.
The null hypothesis is:
statistic |
test statistic with a names attribute that lists the statistic:
| ||||
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. |
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)