kw.test | R Documentation |
Performs a test for trend in an r x c
contingency table with
one nominal (rows, r > 2) and one ordinal (columns, c > 2) variable.
kw.test(x, ...)
## Default S3 method:
kw.test(x, g, ..., simulate.p.value = FALSE, B = 2000L)
## S3 method for class 'formula'
kw.test(formula, data, ...)
x |
a factor-like vector giving the (unordered) variable (equivalently
the row variable of a contingency table); if alternatively, |
... |
further arguments to be passed to or from methods |
g |
a factor-like vector giving the ordered group for each
corresponding element of |
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
|
A list with class "htest
" containing the following elements:
statistic |
the chi-squared test statistic |
parameter |
the degrees of freedom of the approximate chi- squared distribution of the test statistic |
p.value |
the p-value of the test (two-sided) |
method |
a character string describing the test, and, optionally, the number of Monte Carlo replications, if applicable |
data.name |
a character string giving the names of the data |
conf.int |
optionally (if |
summary |
optionally (if |
jt.test
for doubly-ordered tables; cuzick.test
;
ca.test
; DescTools::CochranArmitageTest
;
prop.trend.test
## example from Exact Test (Mehta), figure 11.1
## system.file('docs', 'PASW_Exact_Tests.pdf', package = 'rawr')
dat <- data.frame(
regimen = rep(c('CTMX', 'CCNU', 'MTX', 'CTX+CCNU', 'CTX+CCNU+MTX'),
times = c(2, 2, 3, 4, 6)),
response = c('NR', 'NR', 'NR', 'PR', 'NR', 'NR', 'NR',
'NR', 'NR', 'PR', 'PR', 'NR', 'PR', 'CR', 'CR', 'CR', 'CR')
)
dat$response2 <- factor(dat$response, c('NR', 'PR', 'CR'))
kw.test(dat$regimen, dat$response) ## incorrect
kw.test(dat$regimen, dat$response2) ## correct
## the following are equivalent to the above
kw.test(dat$regimen ~ dat$response2)
kw.test(regimen ~ response2, dat)
kw.test(split(dat$regimen, dat$response2))
kw.test(table(dat$regimen, dat$response2))
## compare (note formula is reversed)
kruskal.test(response2 ~ regimen, dat)
## Not run:
## simulate p-value with 5k replicates
set.seed(1)
kw.test(regimen ~ response2, dat, simulate.p.value = TRUE, B = 5000)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.