cuzick.test | R Documentation |
An implementation of Cuzick's extension of the Wilcoxon rank-sum test to assess trend in data with three or more ordinal groups.
cuzick.test(x, ...)
## Default S3 method:
cuzick.test(
x,
g,
details = wilcox.test,
correct = TRUE,
...,
simulate.p.value = FALSE,
B = 2000L
)
## S3 method for class 'formula'
cuzick.test(formula, data, ...)
x |
a numeric vector of data values or a list of numeric data vectors;
non-numeric elements of a list will be coerced with a warning; if |
... |
additional arguments passed to the function given by
|
g |
a vector or factor object giving the group for the corresponding
elements of |
details |
|
correct |
logical; if |
simulate.p.value |
logical; if |
B |
an integer specifying the number of replicates used in the Monte Carlo test |
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
Data are assumed to be from independent groups with a natural or
meaningful order. If x
and g
are given as vectors and
g
is a factor, the order of levels(g)
will be respected;
however, if g
is not a factor, it will be coerced, and the
levels will be the same as levels(factor(g))
.
For example, if g
is (a character string of) c("5mg", "10mg",
"15mg")
, then the groups will be ordered as "10mg" "15mg" "5mg"
which may not be desired.
Pairwise comparisons between each pair of groups is performed using the
function given by details
(default is wilcox.test
);
the overall will be compared by kruskal.test
. Other functions
may be used (e.g., in cases with ties), but these need a formula method
similar to cuzick.test
, wilcox.test
, etc. Common methods such
as wilcox_test
or kruskal_test
from
the coin package will work; see examples.
A list with class "htest
" containing the following elements:
statistic |
the value of the test statistic with a name describing it |
p.value |
the p-value for the test (two-sided, (un)corrected for ties) |
estimate |
the medians by group |
method |
a character string describing the test used |
data.name |
a character string giving the names of the data |
details |
a list of pairwise ( |
conf.int |
optionally, (if |
summary |
optionally (if |
Altman, D. G. 1991. Practical Statistics for Medical Research. London: Chapman & Hall/CRC.
Cuzick, J. 1985. A Wilcoxon-type test for trend. Statistics in Medicine 4: 87-90.
kruskal.test
; wilcox.test
kruskal_test
; wilcox_test
from the
coin package
## Altman (1991), 217
## ocular exposure to ultraviolet radiation for 32 pairs of sunglasses
## classified into three groups according to the amount of visible light
## transmitted
x <- list(c(1.4, 1.4, 1.4, 1.6, 2.3, 2.5),
c(0.9, 1.0, 1.1, 1.1, 1.2, 1.2,
1.5, 1.9, 2.2, 2.6, 2.6, 2.6,
2.8, 2.8, 3.2, 3.5, 4.3, 5.1),
c(0.8, 1.7, 1.7, 1.7, 3.4, 7.1, 8.9, 13.5))
cuzick.test(x, correct = FALSE)
## equivalent ways to call cuzick.test
cuzick.test(x)
cuzick.test(unlist(x), rep(seq_along(x), lengths(x)))
cuzick.test(x ~ g, data.frame(x = unlist(x), g = rep(1:3, lengths(x))))
## all pairwise comparisons are returned by default in $details
cuzick.test(x)$details
cuzick.test(x, alternative = 'less', correct = FALSE)$details
cuzick.test(x, details = kruskal.test)$details
cuzick.test(x, details = t.test)$details
# cuzick.test(x, details = coin::wilcox_test)$details
## Cuzick (1985), 87-90
## mice inoculated with five cell lines which had been selected for their
## increasing metastatic potential; number of lung metastases found in each
## mouse after inoculation
x <- list(
'CMT 64' = c(0, 0, 1, 1, 2, 2, 4, 9),
'CMT 167' = c(0, 0, 5, 7, 8, 11, 13, 23, 25, 97),
'CMT 170' = c(2, 3, 6, 9, 10, 11, 11, 12, 21),
'CMT 175' = c(0, 3, 5, 6, 10, 19, 56, 100, 132),
'CMT 181' = c(2, 4, 6, 6, 6, 7, 18, 39, 60)
)
cuzick.test(x)$p.value / 2 ## one-sided (corrected for ties)
## coercing character group vector g to factor may have undesired order
set.seed(1)
x <- sort(rnorm(20))
g1 <- sample(paste0(c(5, 10, 15), 'mg'), 20, replace = TRUE)
g2 <- factor(g1, levels = paste0(c(5, 10, 15), 'mg'))
## wrong order
tplot(x ~ g1, data.frame(x, g1), type = 'db', test = cuzick.test)
## correct order
tplot(x ~ g2, data.frame(x, g2), type = 'db', test = cuzick.test)
## groups need not be equally-spaced but will affect statistic/p-value
set.seed(1)
x <- sort(rnorm(20))
g1 <- sample(1:3, 20, replace = TRUE)
g2 <- g1 + (g1 == 3)
tplot(x, g1, test = cuzick.test)
tplot(x, g2, test = cuzick.test)
## compare
tplot(x, factor(g2), test = cuzick.test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.