R软件中的wilcox.test()检验
(2012-03-13 17:41:42)
标签:
杂谈 |
| wilcox.test {stats} | R Documentation |
Wilcoxon Rank Sum and Signed Rank Tests
Description
Performs one- and two-sample Wilcoxon tests on vectors of data; the latter is also known as ‘Mann-Whitney’ test.
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 |
numeric vector of data values. Non-finite (e.g. infinite or missing) values will be omitted. |
y |
an optional
numeric vector of data values: as
with x |
alternative |
a character
string specifying the alternative hypothesis, must be one
of "two.sided" "greater" "less".
You can specify just the initial letter. |
mu |
a number specifying an optional parameter used to form the null hypothesis. See ‘Details’. |
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. |
formula |
a formula of
the form lhs ~
rhs lhs rhs |
data |
an optional
matrix or data frame (or similar:
see model.frame) containing
the variables in the formulaformula. By default the
variables are taken
from environment(formula). |
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function
which indicates what should happen when the data
contain NAs. Defaults
togetOption("na.action"). |
... |
further arguments to be passed to or from methods. |
Details
The formula interface is only applicable for the 2-sample tests.
If only x x y paired TRUE,
a Wilcoxon signed rank test of the null that the distribution
of x x -
y mu
Otherwise, if
both x y paired FALSE,
a Wilcoxon rank sum test (equivalent to the Mann-Whitney test: see
the Note) is carried out. In this case, the null hypothesis is that
the distributions
of x y mu "greater"is
that x y).
By default
(if exact
Optionally (if
argument conf.int x-y x y.
If exact p-values are available, an exact confidence interval is
obtained by the algorithm described in Bauer (1972), and the
Hodges-Lehmann estimator is employed. Otherwise, the returned
confidence interval and point estimate are based on normal
approximations. These are continuity-corrected for the interval
but alternative).
With small samples it may not be possible to achieve very high confidence interval coverages. If this happens a warning will be given and an interval with lower coverage will be substituted.
Value
A list with
class "htest"
statistic |
the value of the test statistic with a name describing it. |
parameter |
the parameter(s) for the exact distribution of the test statistic. |
p.value |
the p-value for the test. |
null.value |
the location
parameter mu. |
alternative |
a character string describing the alternative hypothesis. |
method |
the type of test applied. |
data.name |
a character string giving the names of the data. |
conf.int |
a confidence
interval for the location parameter. (Only present if
argument conf.int = TRUE.) |
estimate |
an estimate
of the location parameter. (Only present if
argument conf.int = TRUE.) |
Warning
This function can use large amounts of memory and stack (and
even crash exact =
TRUE
Note
The literature is not unanimous about the definitions of the
Wilcoxon rank sum and Mann-Whitney tests. The two most common
definitions correspond to the sum of the ranks of the first sample
with the minimum value subtracted or
not:
R's value can also be computed as the
number of all pairs (x[i],
y[j]) y[j] x[i], the most common
definition of the Mann-Whitney test.
References
David F. Bauer (1972), Constructing confidence sets using rank
statistics.
Myles Hollander and Douglas A. Wolfe
(1973),
Or second edition (1999).
See Also
wilcox_test
kruskal.test t.test
Examples
require(graphics)
## 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.test(x, y, paired = TRUE, alternative = "greater")
wilcox.test(y - x, alternative = "less") # The same.
wilcox.test(y - x, alternative = "less",
exact = FALSE, correct = FALSE) # H&W large sample
# approximation
## 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.test(x, y, alternative = "g") # greater
wilcox.test(x, y, alternative = "greater",
exact = FALSE, correct = FALSE) # H&W large sample
# approximation
wilcox.test(rnorm(10), rnorm(10, 2), conf.int = TRUE)
## Formula interface.
boxplot(Ozone ~ Month, data = airquality)
wilcox.test(Ozone ~ Month, data = airquality,
subset = Month %in% c(5, 8))

加载中…