Skip to contents

Calculates the confidence interval for the Mantel-Haenszel estimate of the common risk difference across multiple 2x2 tables (strata), using the Sato variance estimator.

Usage

ci_risk_diff_mh_strata(x, by, strata, conf.level = 0.95, data = NULL)

Arguments

x

(binary/numeric/logical)
vector of a binary values, i.e. a logical vector, or numeric with values c(0, 1)

by

(string)
A character or factor vector with exactly two unique levels identifying the two groups to compare. Can also be a column name if a data frame provided in the data argument.

strata

(numeric)
A vector specifying the stratum for each observation. It needs to be the length of x or a multiple of x if multiple levels of strata are present. Can also be a column name (or vector of column names NOT quoted) if a data frame provided in the data argument.

conf.level

(scalar numeric)
a scalar in (0,1) indicating the confidence level. Default is 0.95

data

(data.frame)
Optional data frame containing the variables specified in x and by.

Value

An object containing the following components:

estimate

The Mentel-Haeszel estimated common risk difference

conf.low

Lower bound of the confidence interval

conf.high

Upper bound of the confidence interval

conf.level

The confidence level used

variance

Sato variance estimate

statistic

Z-Statistic under the null hypothesis, assuming a common risk difference of 0

p.value

p-value under the null hypothesis, assuming a common risk difference of 0

method

Description of the method used ("Mentel-Haenszel Confidence Interval, Sato Variance")

Details

The Mantel-Haenszel common risk difference is computed as:

$$\hat{\delta}_{MH} = \frac{\sum_{k} w_k \hat{\delta}_k }{\sum_{k} w_k}$$

where \(w_k = \frac{n_{xk} n_{yk}}{N_k}\), \(\hat{\delta}_k = s_{xk}/n_{xk} - y_{yk}/n_{yk}\), \(N_k = n_{xk} + n_{yk}\), \(s_{xk}\) and \(s_{yk}\) are the number of events in each group, and \(n_{xk}\), and \(n_{yk}\) are the group sizes in stratum \(k\).

The Sato variance is:

$$\hat{\sigma}^2(\hat{\delta}_{MH}) = \frac{\hat{d}_{MH} \sum_{k}{P_k} + \sum_k Q_k}{\left( \sum_k w_k \right)^2}$$

where \(P_k = \frac{n_{xk}^2 s_{yk} - n_{yk}^2 s_{xk} + n_{xk} n_{yk} (n_{yk} - n_{xk})/2}{N_k^2}\) and \(Q_k = \frac{s_{xk}(n_{yk} - s_{yk}) + s_{yk}(n_{xk} - s_{xk})}{2 N_k}\).

The confidence interval is then \(\hat{\delta}_{MH} \pm z_{1-\alpha/2} \sqrt{\hat{\sigma}^2(\hat{d}_{MH})}\).

References

Agresti, A. (2013). Categorical Data Analysis. 3rd Edition. John Wiley & Sons, Hoboken, NJ p. 231

Examples

# Generate binary samples with strata
responses <- expand(c(9, 3, 7, 2), c(10, 10, 10, 10))
arm <- rep(c("treat", "control"), 20)
strata <- rep(c("stratum1", "stratum2"), times = c(20, 20))

# Calculate common risk difference
ci_risk_diff_mh_strata(x = responses, by = arm, strata = strata)
#> 
#> ── Mentel-Haenszel Risk Difference Confidence Interval, Sato Variance ──────────
#> • 12/20 - 9/20
#> • Estimate: 0.15
#> • Variance: 0.024
#> • 95% Confidence Interval:
#>   (-0.1528, 0.4528)