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 HYPOTHESIS:

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 ASSUMPTIONS:

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:

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:

, , , .

EXAMPLES:

# Data from Hollander and Wolfe (1973), p. 116 
holl.y <- 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.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 <- 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 'y' and 'groups': 
y2 <- as.vector(tab.data) 
gr <- factor(as.vector(col(tab.data)))   # Groups are columns 
kruskal.test(y2, gr)