mantelHaenszel: Cochran-Mantel-Haenszel Chi-Squared Test for Count Data

View source: R/mantelHaenszel.R

mantelHaenszelR Documentation

Cochran-Mantel-Haenszel Chi-Squared Test for Count Data

Description

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.

Usage

mantelHaenszel(exposure, outcome, stratum)

Arguments

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 exposure and outcome belong.

Value

tab

Table that counts numbers of strata for each case-control combination.

test.stat

Test statistic for chi^2 test.

p.val

p-value of chi^2 test.

Author(s)

Kaspar Rufibach
kaspar.rufibach@gmail.com

References

Agresti, A. (2002). Categorical data analysis. Wiley, New York,

See Also

Similar functionality is provided in mantelhaen.test and clogit. See the examples below for a comparison.

Examples


# 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


felix-hof/biostatUZH documentation built on Sept. 27, 2024, 1:48 p.m.