kruskal.test
Kruskal-Wallis Rank Sum Test

Description

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

Usage

kruskal.test(x, ...)
## Default S3 method:
kruskal.test(x, g, ...)
## S3 method for class 'formula':
kruskal.test(formula, data, subset, na.action, ...)

Arguments

x a numeric vector or a list of observations that contain the sample values. If the data is a list, the list must have more than one element and the elements must specify groups. Missing values (NAs) are ignored. However, because infinite values (Infs) are rankable they are not removed.
g a factor object that specifies the group (treatment) for each corresponding element of x. If g is not a factor object, it will be coerced to one. length(g) must be eqaul to length(x).

If x is a list, this argument is ignored.

Missing values (NAs) and infinite values (Infs) are not allowed.

formula a formula or terms that describe the model. In general, formulas follow the pattern, a ~ b | c, where a specifies the data values, b specifies the groups, and c specifies the blocks.
data a data frame or matrix that contains the objects named in formula. By default, this argument reads in values from parent.frame() and you do not need to call this argument explicitly. However, if parent.frame() contains a matrix, you must use the data argument.
subset a vector that specifies a subset from the data frame (data) to use in formula.
na.action a character string that specifies how missing values (NAs) are handled. By default, an error is returned.
... any other arguments that are appropriate for the particular call.
Value
returns a list of class htest, containing the following components:
statistic the Kruskal-Wallis chi-square statistic, with names attribute Kruskal-Wallis chi-square.
parameter the degrees of freedom of the asymptotic chi-square distribution associated with statistic with the names attribute df.
p.value the asymptotic p-value for the test.
method character string giving the name of the method used. Currently, it is always Kruskal-Wallis rank sum test.
data.name a character string (vector of length 1) containing the actual names of the input arguments x and g.
Null hypothesis
In the context of a one-way layout with factor g, a typical null hypothesis is that the true location parameter for x is the same in each of the g. The alternative hypothesis is that it is different in at least one of the g. For alternate models see Hollander and Wolfe (1973).
Test assumptions
The elements of x are assumed to consist of a g effect plus independent and identically distributed residual errors.
You should interpret the returned p.value carefully because it is only a large-sample approximation whose validity increases with the smallest of the group sizes.
References
Hollander, M. and Wolfe, D. A. 1973. Nonparametric Statistical Methods. New York, NY: John Wiley & Sons. 115-120.
Lehmann, E. L. 1975. Nonparametrics: Statistical Methods Based on Ranks. Oakland, CA: Holden-Day.
See Also
wilcox.test, friedman.test, aov, rank.
Examples
# Data from Hollander and Wolfe (1973), p. 116 
holl.x <- c(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 <- factor(c(1,1,1,1,1,2,2,2,2,3,3,3,3,3), 
     labels=c("Normal Subjects","Obstr. Airway Disease","Asbestosis"))
kruskal.test(holl.x, 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 <- matrix(c(.38,.58,.15,.72,.09,.66,.52,.02,.59,.94, .24,.94,.08,.97,.47,.92,.59,.77), ncol=3) tab.data # Generate 'x' and 'g': x2 <- as.vector(tab.data) gr <- factor(as.vector(col(tab.data))) # Groups are columns kruskal.test(x2, gr)

Package stats version 6.0.0-69
Package Index