Kruskal-Wallis Rank Sum Test

DESCRIPTION:
Performs a Kruskal-Wallis rank sum test on data following a one-way layout.

USAGE:
kruskal.test(y, groups)

REQUIRED ARGUMENTS:
y:
numeric vector of observations. NAs are allowed, but will be removed. Infs are allowed, and are not removed as they are rankable.
groups:
factor or category object of the same length as y, giving the group (treatment) for each corresponding element of y. NAs and Infs are not allowed. If groups is not a factor or category object, it will be coerced to one.

VALUE:
A list of class "htest", containing the following components:

statistic:
the Kruskal-Wallis chi-square statistic, with names attribute "Kruskal-Wallis chi-square". See section DETAILS for a definition.
parameters:
the degrees of freedom of the asymptotic chi-square distribution associated with statistic. Component parameters has names attribute "df".
p.value:
the asymptotic p-value for the test.
alternative:
always "two.sided", to reflect that the implicit alternative hypothesis is two-sided.
method:
character string giving the name of the method used.
data.name:
a character string (vector of length 1) containing the actual names of the input arguments y and groups.


NULL:
In the context of a one-way layout with factor groups, a typical null hypothesis is that the true location parameter for y is the same in each of the groups. The alternative hypothesis is that it is different in at least one of the groups. See Hollander and Wolfe (1973) for alternate models.


TEST:
The elements of y are assumed to consist of a groups effect plus independent and identically distributed residual errors.

The returned p.value should be interpreted carefully. It is only a large-sample approximation whose validity increases with the smallest of the group sizes.


DETAILS:
See the hardcopy help-file for an algebraic definition of the statistic.

Under the null hypothesis, the Kruskal-Wallis statistic has an asymptotic chi-square distribution with k - 1 degrees of freedom, where k is the number of groups.


REFERENCES:
Hollander, M. and Wolfe, D. A. (1973). Nonparametric Statistical Methods. New York: John Wiley.

Lehmann, E. L. (1975). Nonparametrics: Statistical Methods Based on Ranks. Oakland, Calif.: Holden-Day.


SEE ALSO:
wilcox.test , friedman.test , aov , rank .

EXAMPLES:
holl.y         # data from Hollander and Wolfe (1973), p. 116
[1] 2.9 3.0 2.5 2.6 3.2 3.8 2.7 4.0 2.4 2.8 3.4 3.7 2.2 2.0
holl.grps      # a category object
[1] 1 1 1 1 1 2 2 2 2 3 3 3 3 3
attr(, "levels"):
[1] "Normal Subjects"       "Obstr. Airway Disease" "Asbestosis"
kruskal.test(holl.y, holl.grps)
# Now suppose the data is in the form of a table already,
# with groups in columns; note this implies that group
# sizes are the same.
tab.data                 # fictional matrix of data
     Grp 1 Grp 2 Grp 3
Obs1  0.38  0.52  0.08
Obs2  0.58  0.02  0.97
Obs3  0.15  0.59  0.47
Obs4  0.72  0.94  0.92
Obs5  0.09  0.24  0.59
Obs6  0.66  0.94  0.77
# generate 'y' and 'groups':
y2 <- as.vector(tab.data)
gr <- factor(as.vector(col(tab.data)))   # if groups are columns
kruskal.test(y2, gr)