View source: R/mantelHaenszel.R
mantelHaenszel | R Documentation |
Compute Cochran-Mantel-Haenszel chi-squared test of the null that two nominal variables are conditionally independent in each stratum, assuming that there is no three-way interaction.
mantelHaenszel(exposure, outcome, stratum)
exposure |
Binary variable coding whether patient was exposed (1) or not (0). |
outcome |
Binary variable coding outcome of patient. |
stratum |
Factor object with at least 2 levels identifying to which
stratum the corresponding elements in |
tab |
Table that counts numbers of strata for each case-control combination. |
test.stat |
Test statistic for |
p.val |
|
Kaspar Rufibach
kaspar.rufibach@gmail.com
Agresti, A. (2002). Categorical data analysis. Wiley, New York,
Similar functionality is provided in mantelhaen.test
and clogit
. See the examples below for a
comparison.
# generate data
set.seed(1977)
data <- data.frame(exposure = rep(c(1, 0, 0, 0, 0), 41),
outcome = sample(x = c(rep(1, 62), rep(0, 5 * 41 - 62))),
stratum = rep(1:41, each = 5))
# via conditional logistic regression
logreg <- clogit(outcome ~ exposure + strata(stratum), method = "approximate",
data = data)
summary(logreg)
# R function in library 'stats'
mh <- with(data, mantelhaen.test(x = outcome, y = exposure, z = stratum))
# this function
mH <- with(data, mantelHaenszel(exposure = exposure,
outcome = outcome,
stratum = stratum))
# compare p-values
summary(logreg)$coef[5]
mh$p.value
mH$p.val
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.