Functions & Formulae

Each applied formula has its own function page, with a signature, implementations, and tests.

Mantel-Haenszel pooling and test of association across stratified two-by-two tables

mh(a_i, b_i, c_i, d_i) = (OR_MH, RR_MH, RD_MH, chi2_MH)

Maps the cell counts of several two-by-two tables, one per trial or stratum, to a pooled odds ratio, risk ratio or risk difference with its standard error, and to a test of association, while keeping each comparison inside its own stratum. HE-FM-MHM-001 to HE-FM-MHM-003 give the estimators and HE-FM-MHM-004 the Cochran-Mantel-Haenszel statistic, each written out for two strata so that the calculator runs. Their Excel rows take any number of strata, and HE-CF-MHM-001 chains all four for three trials. Another common-effect weighting is the inverse-variance estimate HE-FM-ADMA-001, which HE-FM-PWMA-001 feeds for a risk ratio. The risk difference of one trial is HE-FM-ARR-001 with the sign reversed. Applying a pooled ratio to a baseline probability takes the form of HE-FM-NMA-004 for an odds ratio, written there for a network odds ratio, and is HE-FM-ARR-002 for a risk ratio. Notation follows the Mantel-Haenszel Method article.

  • Mantel-Haenszel pooled odds ratio with its Robins, Breslow and Greenland standard error

    N_1 = a_1 + b_1 + c_1 + d_1; N_2 = a_2 + b_2 + c_2 + d_2; R = a_1 * d_1 / N_1 + a_2 * d_2 / N_2; S = b_1 * c_1 / N_1 + b_2 * c_2 / N_2; E = (a_1 + d_1) * a_1 * d_1 / N_1^2 + (a_2 + d_2) * a_2 * d_2 / N_2^2; F = (a_1 + d_1) * b_1 * c_1 / N_1^2 + (a_2 + d_2) * b_2 * c_2 / N_2^2; G = (b_1 + c_1) * a_1 * d_1 / N_1^2 + (b_2 + c_2) * a_2 * d_2 / N_2^2; H = (b_1 + c_1) * b_1 * c_1 / N_1^2 + (b_2 + c_2) * b_2 * c_2 / N_2^2; OR_MH = R / S; lnOR_MH = log(OR_MH); SE_lnOR = sqrt(0.5 * (E / R^2 + (F + G) / (R * S) + H / S^2)); OR_L = exp(lnOR_MH - 1.96 * SE_lnOR); OR_U = exp(lnOR_MH + 1.96 * SE_lnOR)

    Adds a d / N over the strata to give R and b c / N to give S, then divides R by S. The result equals the average of the study odds ratios weighted by b c / N, so the weights rest on counts and group sizes with no estimated variance for each study. The standard error of its natural log combines R, S and the four sums E, F, G and H, as RevMan does in its equation 2. The interval takes the form of HE-FM-NMA-002, which computes it for an indirect comparison, with lnOR_MH in place of d_BC and SE_lnOR squared in place of V_BC. Two strata are written out, and each further stratum adds one term to every sum.

  • Mantel-Haenszel pooled risk ratio with its standard error

    N_1 = n1_1 + n2_1; N_2 = n1_2 + n2_2; R_RR = a_1 * n2_1 / N_1 + a_2 * n2_2 / N_2; S_RR = c_1 * n1_1 / N_1 + c_2 * n1_2 / N_2; P = (n1_1 * n2_1 * (a_1 + c_1) - a_1 * c_1 * N_1) / N_1^2 + (n1_2 * n2_2 * (a_2 + c_2) - a_2 * c_2 * N_2) / N_2^2; RR_MH = R_RR / S_RR; lnRR_MH = log(RR_MH); SE_lnRR = sqrt(P / (R_RR * S_RR)); RR_L = exp(lnRR_MH - 1.96 * SE_lnRR); RR_U = exp(lnRR_MH + 1.96 * SE_lnRR)

    Adds a n2 / N over the strata to give R_RR and c n1 / N to give S_RR, then divides. The result equals the average of the study risk ratios of HE-FM-PWMA-001 weighted by c n1 / N. The standard error of the natural log comes from the sum P and the two sums already formed, as in RevMan's equation 4. The interval takes the form of HE-FM-NMA-002, which computes it for an indirect comparison, with lnRR_MH in place of d_BC and SE_lnRR squared in place of V_BC. Applying RR_MH to a baseline risk is HE-FM-ARR-002.

  • Mantel-Haenszel pooled risk difference with its standard error

    N_1 = n1_1 + n2_1; N_2 = n1_2 + n2_2; RD_1 = a_1 / n1_1 - c_1 / n2_1; RD_2 = a_2 / n1_2 - c_2 / n2_2; w_1 = n1_1 * n2_1 / N_1; w_2 = n1_2 * n2_2 / N_2; K = w_1 + w_2; J = (a_1 * (n1_1 - a_1) * n2_1^3 + c_1 * (n2_1 - c_1) * n1_1^3) / (n1_1 * n2_1 * N_1^2) + (a_2 * (n1_2 - a_2) * n2_2^3 + c_2 * (n2_2 - c_2) * n1_2^3) / (n1_2 * n2_2 * N_2^2); RD_MH = (w_1 * RD_1 + w_2 * RD_2) / K; SE_RD = sqrt(J / K^2); RD_L = RD_MH - 1.96 * SE_RD; RD_U = RD_MH + 1.96 * SE_RD

    Averages the study risk differences with weights n1 n2 / N, as in RevMan's equation 5. Each RD is HE-FM-ARR-001 with the sign reversed, since this record takes the new treatment minus the comparator, as the Cochrane Handbook does. The weight depends only on the group sizes, and it is neither the inverse variance of HE-FM-ADMA-001 nor a share of patients, so a trial randomised 2 to 1 counts for less than its total size suggests. The standard error comes from J and K as in RevMan's equation 6, and the limits are the interval of HE-FM-AN-001 with z equal to 1.96.

  • Cochran-Mantel-Haenszel test statistic for stratified two-by-two tables

    N_1 = n1_1 + n2_1; N_2 = n1_2 + n2_2; M_1 = a_1 + c_1; M_2 = a_2 + c_2; E_1 = n1_1 * M_1 / N_1; E_2 = n1_2 * M_2 / N_2; V_1 = n1_1 * n2_1 * M_1 * (N_1 - M_1) / (N_1^2 * (N_1 - 1)); V_2 = n1_2 * n2_2 * M_2 * (N_2 - M_2) / (N_2^2 * (N_2 - 1)); D_MH = (a_1 - E_1) + (a_2 - E_2); V_MH = V_1 + V_2; chi2_MH = D_MH^2 / V_MH

    Tests the null hypothesis that treatment and outcome are independent within every stratum. Given the margins of a table, a follows a hypergeometric distribution with mean E and variance V, the expressions RevMan prints in its Peto section. The observed minus expected counts are added over strata before squaring, so differences in the same direction accumulate, and the square is divided by the summed variance. The statistic is compared with a chi-square distribution on one degree of freedom, and D_MH / sqrt(V_MH) is the z of HE-FM-CHISQ-005. The sign of D_MH gives the direction.

This set of formulae is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).

Author: Dr Darrin Baines · Publisher: Intelligent Parameters Ltd · Identifier: https://healtheconomics.wiki/concept/mantel-haenszel-method/formulae