rm(list=ls())
library(RobinCar)

Please see Qiu, Qian, Yi, Wang, Du, Yi, Ye (2025) for more information about the Mantel-Haenszel estimator.

Mantel Haenszel Statistic

The dataset that we will use for this is included in the package.

data <- RobinCar:::data_sim
data <- data[data$A != 2, ]
data$A <- as.factor(data$A)
data$y_bin <- ifelse(data$y > 2, 1, 0)

Estimate MH risk difference

fit.MHrd.mGR <- robincar_mh(
  df = data,
  treat_col = "A",
  response_col = "y_bin",
  strata_cols = c("z1", "z2"),
  estimand = "MH",
  ci_type = "mGR"
)

fit.MHrd.mGR
#> Treatment group contrasts based on Mantel-Haenszel risk difference
#> Estimand: Mantel-Haenszel risk difference
#> Stratified by z1, z2
#> SE calculated via modified Greenland's estimator
#> 
#> Contrasts:
#> # A tibble: 1 × 4
#>   contrast    estimate     se `pval (2-sided)`
#>   <chr[1d]>      <dbl>  <dbl>            <dbl>
#> 1 treat 1 - 0    0.218 0.0359    0.00000000123

Estimate Average Treatment Effect

fit.ATE.mGR <- robincar_mh(
  df = data,
  treat_col = "A",
  response_col = "y_bin",
  strata_cols = c("z1", "z2"),
  estimand = "ATE",
  ci_type = "mGR"
)

fit.ATE.mGR
#> Treatment group contrasts based on ATE
#> Estimand: ATE
#> Stratified by z1, z2
#> SE calculated via modified Greenland's estimator
#> 
#> Contrasts:
#> # A tibble: 1 × 4
#>   contrast    estimate     se `pval (2-sided)`
#>   <chr[1d]>      <dbl>  <dbl>            <dbl>
#> 1 treat 1 - 0    0.218 0.0449       0.00000114