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

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

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:

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:

treatments <- factor(rep(c("Trt1", "Trt2", "Trt3"), each=4))
people <- factor(rep(c("Subject1", "Subject2", "Subject3", "Subject4"), 3))
y <- c(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, rows are people and
#   columns are treatments.
# Generate 'ymat' and the factor objects: 
ymat <- matrix(c(0.73,0.76,0.46,0.85,0.48,0.78,0.87,0.22,0.51,
     0.03,0.39,0.44), ncol=3)
bl <- factor(as.vector(row(ymat)))
gr <- factor(as.vector(col(ymat)))   
friedman.test(ymat, gr, bl)  # same answer as above