kruskal.test(x, ...) ## Default S3 method: kruskal.test(x, g, ...) ## S3 method for class 'formula': kruskal.test(formula, data, subset, na.action, ...)
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. |
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. |
# 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)