ci_prop_diff_mn | R Documentation |
Calculates the Miettinen-Nurminen (MN) confidence interval for the difference between two proportions. This method can be more accurate than traditional methods, especially with small sample sizes or proportions close to 0 or 1.
ci_prop_diff_mn(x, by, conf.level = 0.95, delta = NULL, data = NULL)
x |
( |
by |
( |
conf.level |
( |
delta |
( |
data |
( |
The function implements the Miettinen-Nurminen method to compute confidence intervals for the difference between two proportions. This approach:
Calculates the Miettinen-Nurminen score test statistic for different possible values of the proportion difference (delta)
Identifies the delta values where the test statistic equals the critical value corresponding to the desired confidence level
Returns these boundary values as the confidence interval limits
The method uses a score test with a small-sample correction factor, making it more accurate than normal approximation methods, especially for small samples or extreme proportions. The equation for the test statistics is as follows:
H_0: \hat{d}-\delta <= 0 \qquad \text{vs.} \qquad H_1: \hat{d}-\delta > 0
T_\delta = \frac{\hat{p_x} - \hat{p_y} - \delta}{\sigma_{mn}(\delta)}
where \hat{p_*} = s_*/n_*
represent the observed number of successes
divided by the number of participant in that group. The \sigma_{mn}(\delta)
is a
function of the delta values and is create with the following equation"
\tilde{p_*}
represent the MLE of the proportions.
\sigma_{mn}(\delta) = \sqrt{\left[\frac{\tilde{p_y}(1-\tilde{p_y})}{n_x}+\frac{\tilde{p_x}(1-\tilde{p_x})}{n_y} \right]\left(\frac{N}{N-1}\right)}
\tilde{p_x} = 2p\cdot{cos(a)} - \frac{L_2}{3L_3}
and \tilde{p_y} = \tilde{p_x} + \delta
where:
p = \pm \sqrt{\frac{L_2^2}{(3L_3)^2} - \frac{L_1}{3L_3}}
a = 1/3[\pi + cos^{-1}(q/p^3)]
q = \frac{L_2^3}{(3L_3)^3} - \frac{L_1L_2}{6L_3^2} + \frac{L_0}{2L_3}
L_3 = n_x + n_y
L_2 = (n_x + 2 n_y)\delta - N - (s_x + s_y)
L_1 = (n_y\delta - L_3 - 2s_y)\delta + s_x + s_y
L_0 = s_y\delta(1-\delta)
For more information about these equations see Miettinen (1985)
An object containing the following components:
estimate |
The point estimate of the difference in proportions (p_x - p_y) |
conf.low |
Lower bound of the confidence interval |
conf.high |
Upper bound of the confidence interval |
conf.level |
The confidence level used |
delta |
delta value(s) used |
statistic |
Z-Statistic under the null hypothesis based on the given 'delta' |
p.value |
p-value under the null hypothesis based on the given 'delta' |
method |
Description of the method used ("Miettinen-Nurminen Confidence Interval") |
If delta
is not provided statistic and p.value will be NULL
Miettinen, O. S., & Nurminen, M. (1985). Comparative analysis of two rates. Statistics in Medicine, 4(2), 213-226.
# Generate binary samples
responses <- expand(c(9, 3), c(10, 10))
arm <- rep(c("treat", "control"), times = c(10, 10))
# Calculate 95% confidence interval for difference in proportions
ci_prop_diff_mn(x = responses, by = arm)
# Calculate 99% confidence interval
ci_prop_diff_mn(x = responses, by = arm, conf.level = 0.99)
# Calculate the p-value under the null hypothesis delta = -0.1
ci_prop_diff_mn(x = responses, by = arm, delta = -0.1)
# Calculate from a data.frame
data <- data.frame(responses, arm)
ci_prop_diff_mn(x = responses, by = arm, data = data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.