Friedman Rank Sum Test

DESCRIPTION:
Performs a Friedman rank sum test with unreplicated blocked data.

USAGE:
friedman.test(y, groups, blocks)

REQUIRED ARGUMENTS:
y:
numeric vector of observations. NAs are allowed, but all data for each block in which at least one element of y is NA 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 or Infs are not allowed. If groups is not a factor or category object, it will be coerced to one.
blocks:
factor or category object of the same length as y, giving the block membership for each corresponding element of y. NAs and Infs are not allowed. If blocks is not a factor or category object, it will be coerced to one.

There must be exactly one element of y corresponding to each combination of the levels of groups and blocks.


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

statistic:
the Friedman chi-square statistic, with names attribute "Friedman 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, groups and blocks.


NULL:
In the context of a two-way layout with factors groups and blocks, a typical null hypothesis is that the true location parameter for y, net of the blocks effect, 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 Friedman test is appropriate for data arising from an unreplicated complete block design: one in which exactly one observation was collected from each experimental unit, or block, under each treatment. The elements of y are assumed to consist of a groups effect, plus a blocks effect, plus independent and identically distributed residual errors. The interaction between groups and blocks is assumed to be zero.

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


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

Under the null hypothesis, the Friedman statistic has an asymptotic chi-square distribution with k - 1 degrees of freedom.


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 , kruskal.test , aov , rank .

EXAMPLES:
treatments      # a category object
[1] 1 1 1 1 2 2 2 2 3 3 3 3
attr(, "levels"):
[1] "Trt 1" "Trt 2" "Trt 3"
people          # a category object
[1] 1 2 3 4 1 2 3 4 1 2 3 4
attr(, "levels"):
[1] "Subject 1" "Subject 2" "Subject 3" "Subject 4"
y # response
[1] 0.73 0.76 0.46 0.85 0.48 0.78 0.87 0.22 0.51 0.03 0.39 0.44
friedman.test(y, treatments, people)
# now suppose the data is in the form of a matrix.
# generate 'y' and the category objects:
y2 <- as.vector(tab.data)
bl <- factor(as.vector(row(tab.data)))   # if blocks are rows
gr <- factor(as.vector(col(tab.data)))   # if groups are columns
friedman.test(y2, gr, bl)                  # same answer as above