Learn R Programming

exactRankTests (version 0.3-6)

wilcox.exact: Wilcoxon Rank Sum and Signed Rank Tests

Description

Performs one and two sample Wilcoxon tests on vectors of data. Version for exactRankTests.

Usage

wilcox.exact(x, y = NULL, alternative = c("two.sided", "less", "greater"),
            mu = 0, paired = FALSE, exact = NULL, correct = TRUE, 
            conf.int = FALSE, conf.level = 0.95)

Arguments

x
numeric vector of data values.
y
an optional numeric vector of data values.
alternative
the alternative hypothesis must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.
mu
a number specifying an optional location parameter.
paired
a logical indicating whether you want a paired test.
exact
a logical indicating whether an exact p-value should be computed.
correct
a logical indicating whether to apply continuity correction in the normal approximation for the p-value.
conf.int
a logical indicating whether a confidence interval should be computed.
conf.level
confidence level of the interval.

Value

  • A list with class "htest" containing the following components:
  • statisticthe value of the test statistic with a name describing it.
  • parameterthis gives the probability of observing the test statistic itself (named as point-prob). Useful for mid-p-values.
  • p.valuethe p-value for the test.
  • null.valuethe location parameter mu.
  • alternativea character string describing the alternative hypothesis.
  • methodthe type of test applied.
  • data.namea character string giving the names of the data.
  • conf.inta confidence interval for the location parameter. (Only present if argument conf.int = TRUE.)

Details

For testing proposes, this version computes p-values and quantiles using the Streitberg-R"ohmel algorithm (both for tied and untied samples).

If only x is given, or if both x and y are given and paired is TRUE, a Wilcoxon signed rank test of the null that the median of x (in the one sample case) or of x-y (in the paired two sample case) equals mu is performed.

Otherwise, if both x and y are given and paired is FALSE, a Wilcoxon rank sum test (equivalent to the Mann-Whitney test) is carried out. In this case, the null hypothesis is that the location of the distributions of x and y differ by mu.

By default (if exact is not specified), an exact p-value is computed if the samples contain less than 50 finite values and there are no ties. Otherwise, a normal approximation is used.

Optionally (if argument conf.int is true), a nonparametric confidence interval for the median (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 obtained by the algorithm described in Bauer (1972). Otherwise, an asymptotic confidence interval is returned.

References

Myles Hollander & Douglas A. Wolfe (1973), Nonparametric statistical inference. New York: John Wiley & Sons. Pages 27--33 (one-sample), 68--75 (two-sample).

David F. Bauer (1972), Constructing confidence sets using rank statistics. Journal of the American Statistical Association 67, 687--690.

See Also

kruskal.test for testing homogeneity in location parameters in the case of two or more samples; t.test for a parametric alternative under normality assumptions.

Examples

Run this code
## One-sample test.
## Hollander & Wolfe (1973), 29f.
## Hamilton depression scale factor measurements in 9 patients with
##  mixed anxiety and depression, taken at the first (x) and second
##  (y) visit after initiation of a therapy (administration of a
##  tranquilizer).
x <- c(1.83,  0.50,  1.62,  2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)
wilcox.exact(x, y, paired = TRUE, alternative = "greater")
wilcox.exact(y - x, alternative = "less")    # The same.

## Two-sample test.
## Hollander & Wolfe (1973), 69f.
## Permeability constants of the human chorioamnion (a placental
##  membrane) at term (x) and between 12 to 26 weeks gestational
##  age (y).  The alternative of interest is greater permeability
##  of the human chorioamnion for the term pregnancy.
x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46)
y <- c(1.15, 0.88, 0.90, 0.74, 1.21)
wilcox.exact(x, y, alternative = "g")        # greater

x <- rnorm(10)
y <- rnorm(10, 2)
wilcox.exact(x, y, conf.int = TRUE)

# Data from the StatXact-4 manual, page 221, diastolic blood pressure

treat <- c(94, 108, 110, 90)
contr <- c(80, 94, 85, 90, 90, 90, 108, 94, 78, 105, 88)

# StatXact 4 for Windows: p.value = 0.0989, point prob = 0.019

wilcox.exact(contr, treat)

# StatXact 4 for Windows: p.value = 0.0542, point prob = 0.019
 
wilcox.exact(contr, treat, alternative="less")

Run the code above in your browser using DataLab