statsmodels.stats.proportion.confint_proportions_paired#
- statsmodels.stats.proportion.confint_proportions_paired(table, method='newcomb', alpha=0.05)[source]#
Confidence interval for the difference of two paired proportions
This assumes that each of
nunits is classified twice as success or failure, for example before and after a treatment, or by two raters, so that the two proportions are correlated. The confidence interval is for the differencep1 - p2of the two marginal proportions.- Parameters:
- tablearray_like
2x2 contingency table of counts,
[[n11, n12], [n21, n22]]. Rows correspond to the first classification and columns to the second, with success in the first row and first column.n12andn21are the discordant counts. The first marginal proportion isp1 = (n11 + n12) / nand the second isp2 = (n11 + n21) / n, wherenis the total count.- method{“newcomb”, “newcombe”, “wald”},
optional Method for computing the confidence interval.
“newcomb” : Newcombe’s method 10, which combines the Wilson score intervals of the two marginal proportions with a correction for the correlation between them. This is the default. The spelling “newcombe” is accepted as an alias; “newcomb” matches the method name in
confint_proportions_2indep.“wald” : simple asymptotic (Wald) interval without continuity correction, Newcombe’s method 1. It degenerates to a zero-width interval when there are no discordant pairs.
- alpha
float,optional Significance level for the confidence interval, default is 0.05. The nominal coverage probability is 1 - alpha.
- Returns:
See also
confint_proportions_2indepConfidence interval for two independent proportions.
statsmodels.stats.contingency_tables.mcnemarHypothesis test for marginal homogeneity of paired binary data.
Notes
Newcombe’s method 10 is the paired analogue of the hybrid score interval recommended for independent proportions in [1]. Let
(l1, u1)and(l2, u2)be the Wilson score limits ofp1andp2, and letphibe the corrected phi coefficient of the table, which is zero if any marginal count is zero. The limits arep1 - p2 - sqrt((p1 - l1)**2 - 2 * phi * (p1 - l1) * (u2 - p2) + (u2 - p2)**2)and
p1 - p2 + sqrt((u1 - p1)**2 - 2 * phi * (u1 - p1) * (p2 - l2) + (p2 - l2)**2).The interval always lies within
[-1, 1]and has positive width even when all pairs are concordant. The Wald interval is not bounded.The results have been verified against the R packages
ratesci(moverpairciwith Wilson base and the phi correction) andPropCIs(diffpropci.Wald.mp).References
[1]Newcombe, Robert G. 1998. “Improved Confidence Intervals for the Difference between Binomial Proportions Based on Paired Data.” Statistics in Medicine 17 (22): 2635-50. https://doi.org/10.1002/(SICI)1097-0258(19981130)17:22<2635::AID- SIM954>3.0.CO;2-C.
Examples
Of 37 patients, 15 respond to treatment A and 12 to treatment B, with 10 responding to both.
>>> from statsmodels.stats.proportion import confint_proportions_paired >>> table = [[10, 5], [2, 20]] >>> confint_proportions_paired(table) (-0.0643926050711..., 0.2211160178958...) >>> confint_proportions_paired(table, method="wald") (-0.0566130751996..., 0.2187752373618...)