Skip to contents

This function implements the Mantel-Haenszel estimators for risk ratio and risk differences for a binary or categorical exposure and one or more categorical confounder(s). Compare to estimates from regression models.

Usage

rr_rd_mantel_haenszel(
  data,
  exposure,
  outcome,
  confounders,
  estimand = c("rr", "rd"),
  conf.level = 0.95
)

Arguments

data

Data set.

exposure

Exposure variable. Must be binary or categorical. The first level is treated as unexposed.

outcome

Outcome variable. Must be binary.

confounders

Optional. Binary or categorical variable(s) to perform stratification over. Supply more than one variable using confounders = c(var1, var2).

estimand

Optional. "rr" for risk ratio; "rd" for risk difference. Defaults to "rr".

conf.level

Optional. Confidence level. Defaults to 0.95.

Value

Tibble in tidy format with

  • term the (non-reference) exposure levels

  • estimate Risk ratio (on log scale) or risk difference

  • std.error, conf.low, and conf.high Square-root of M-H variance estimate, and the corresponding confidence limits (on log scale for RR)

  • model always "mh"

  • estimand "rr" or "rd"

References

Greenland S, Rothman KJ. Introduction to Stratified Analysis. In: Rothman KJ, Greenland S, Lash TL. Modern Epidemiology. 3rd edn. Lippincott Williams & Wilkins: Philadelphia, PA 2008. Page 275. Risk ratios: formulae 15-18, -20, -22. Risk differences: formulae 15-18, -19, -21.

Examples

# Newman SC. Biostatistical methods in epidemiology. New York, NY:
# Wiley, 2001, table 5.3

library(tibble)  # used to set up example data
dat <- tibble(
  death    = c(rep(1, 54), rep(0, 138)),
  stage    = c(rep("Stage I", 7),  rep("Stage II", 26), rep("Stage III", 21),
               rep("Stage I", 60), rep("Stage II", 70), rep("Stage III", 8)),
  receptor = c(rep("Low", 2),  rep("High", 5),  rep("Low", 9),  rep("High", 17),
               rep("Low", 12), rep("High", 9),  rep("Low", 10), rep("High", 50),
               rep("Low", 13), rep("High", 57), rep("Low", 2),  rep("High", 6)))

# Risk difference
rr_rd_mantel_haenszel(
  data = dat,
  exposure = stage,
  outcome = death,
  confounders = receptor,
  estimand = "rd")
#> # A tibble: 2 × 7
#>   term           estimate std.error conf.low conf.high model estimand
#>   <chr>             <dbl>     <dbl>    <dbl>     <dbl> <chr> <chr>   
#> 1 stageStage II     0.159    0.0591   0.0435     0.275 mh    rd      
#> 2 stageStage III    0.573    0.103    0.372      0.775 mh    rd      

# Risk ratio, log scale:
result <- rr_rd_mantel_haenszel(
  data = dat,
  exposure = stage,
  outcome = death,
  confounders = receptor,
  estimand = "rr")
result
#> # A tibble: 2 × 7
#>   term           estimate std.error conf.low conf.high model estimand
#>   <chr>             <dbl>     <dbl>    <dbl>     <dbl> <chr> <chr>   
#> 1 stageStage II     0.918     0.393    0.148      1.69 mh    rr      
#> 2 stageStage III    1.77      0.397    0.992      2.55 mh    rr      

# Risk ratio, exponentiated:
result %>%
  dplyr::mutate(dplyr::across(.cols = c(estimate, conf.low, conf.high),
                              .fns = exp))
#> # A tibble: 2 × 7
#>   term           estimate std.error conf.low conf.high model estimand
#>   <chr>             <dbl>     <dbl>    <dbl>     <dbl> <chr> <chr>   
#> 1 stageStage II      2.50     0.393     1.16      5.41 mh    rr      
#> 2 stageStage III     5.87     0.397     2.70     12.8  mh    rr