Learn R Programming

PMCMRplus (version 1.3.0)

kruskalTest: Kruskal-Wallis Rank Sum Test

Description

Performs a Kruskal-Wallis rank sum test.

Usage

kruskalTest(x, ...)

# S3 method for default kruskalTest(x, g, dist = c("Chisquare", "KruskalWallis", "FDist"), ...)

# S3 method for formula kruskalTest(formula, data, subset, na.action, dist = c("Chisquare", "KruskalWallis", "FDist"), ...)

Arguments

x

a numeric vector of data values, or a list of numeric data vectors.

further arguments to be passed to or from methods.

g

a vector or factor object giving the group for the corresponding elements of "x". Ignored with a warning if "x" is a list.

dist

the test distribution. Defaults's to "Chisquare".

formula

a formula of the form response ~ group where response gives the data values and group a vector or factor of the corresponding groups.

data

an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. 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 to getOption("na.action").

Value

A list with class "htest" containing the following components:

method

a character string indicating what type of test was performed.

data.name

a character string giving the name(s) of the data.

statistic

the estimated quantile of the test statistic.

p.value

the p-value for the test.

parameter

the parameters of the test statistic, if any.

alternative

a character string describing the alternative hypothesis.

estimates

the estimates, if any.

null.value

the estimate under the null hypothesis, if any.

Details

For one-factorial designs with non-normally distributed residuals the Kruskal-Wallis rank sum test can be performed to test the H\(_0: F_1(x) = F_2(x) = \ldots = F_k(x)\) against the H\(_\mathrm{A}: F_i (x) \ne F_j(x)~ (i \ne j)\) with at least one strict inequality.

As the Kruskal-Wallis H-statistic is assymptotically chi-squared distributed with \(v = k - 1\) degree of freedom, the default test distribution is consequently dist = "Chisquare". If dist = "KruskalWallis" is selected, an incomplete beta approximation is used for the calculation of p-values as implemented in the function pKruskalWallis of the package SuppDists. For dist = "FDist" the proposed method of Conover and Imam (1981) is used, which is equivalent to a one-way ANOVA F-test using rank transformed data (see examples).

References

Conover, W. J., Iman, R. L. (1981) Rank transformations as a bridge between parametric and nonparametric statistics, The American Statistician 35, 124--129.

Sachs, L. (1997) Angewandte Statistik. Berlin: Springer.

See Also

kruskal.test, pKruskalWallis, Chisquare, FDist

Examples

Run this code
# NOT RUN {
## Hollander & Wolfe (1973), 116.
## Mucociliary efficiency from the rate of removal of dust in normal
##  subjects, subjects with obstructive airway disease, and subjects
##  with asbestosis.
x <- c(2.9, 3.0, 2.5, 2.6, 3.2) # normal subjects
y <- c(3.8, 2.7, 4.0, 2.4)      # with obstructive airway disease
z <- c(2.8, 3.4, 3.7, 2.2, 2.0) # with asbestosis

datf <- data.frame(
  g = g <- c(rep("ns", length(x)), rep("oad",
      length(y)), rep("a", length(z))),
  x = x <- c(x, y, z))

## Using incomplete beta approximation
kruskalTest(x ~ g, datf, dist="KruskalWallis")

## Using chisquare distribution
kruskalTest(x ~ g, datf, dist="Chisquare")

## Check with kruskal.test from R stats
kruskal.test(x ~ g, datf)

## Using Conover's F
kruskalTest(x ~ g, datf, dist="FDist")

## Check with aov on ranks
anova(aov(rank(x) ~ g, datf))

## Check with oneway.test
oneway.test(rank(x) ~ g, datf, var.equal=FALSE)
# }

Run the code above in your browser using DataLab