twoprop_test: Test of Proportions between 2 Independent Groups

View source: R/two_proportions.R

twoprop_testR Documentation

Test of Proportions between 2 Independent Groups

Description

[Maturing]

This is a hypothesis testing function that mimics prop.test, but focuses only on testing differences in proportions between two groups. This function utilizes a z-test to calculate the p-values (may be inaccurate with small sample sizes).

Usage

twoprop_test(
  p1,
  p2,
  n1,
  n2,
  null = NULL,
  alpha = 0.05,
  alternative = c("two.sided", "less", "greater", "equivalence", "minimal.effect"),
  effect_size = c("difference", "odds.ratio", "risk.ratio")
)

Arguments

p1, p2

Proportions in each respective group.

n1, n2

sample size in each respective group.

null

a number indicating the null hypothesis of the difference in proportions between two groups.

alpha

alpha level (default = 0.05)

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater", "less", "equivalence" (TOST), or "minimal.effect" (TOST). You can specify just the initial letter.

effect_size

the effect size estimate, and confidence intervals, to calculate. Options include the difference between both proportions ("difference"), odds ratio ("odds.ratio"), or risk ratio ("risk.ratio").

Details

The hypothesis test for differences in proportions can be made on the raw proportions scale, the odds ratio, or the risk ratio (details below). This function uses the large sample size asymptotic approximations for both the p-value and confidence interval calculations. There should be a good deal of caution when sample sizes are small. The p-values for the differences in proportions will differ from base prop.test due to the use of the unpooled standard error (see below).

Differences in Proportions

Differences in proportions test is based on the following calculation:

d = p_1 - p_2

The standard error of d is calculated as the following:

se(d) = \sqrt{\frac{p_1 \cdot (1-p_1)}{n_1} + \frac{p_2 \cdot (1-p_2)}{n_2}}

The z-test, with d_0 being the null value, is then calculated as the following (standard normal distribution evaluated to calculate p-value):

z = \frac{d - d_0}{se(d)}

The confidence interval can then be calculated as the following:

d_{lower},d_{upper} = d \pm z_{\alpha} \cdot se(d)

Risk Ratio

The ratio between proportions test is based on the following calculation:

\phi = p_1/p_2

The standard error of ln(\phi) is calculated as the following:

se(ln(\phi)) = \sqrt{\frac{1-p_1}{n_1 \cdot p_1} + \frac{1-p_2}{n_2 \cdot p_2}}

The z-test, with \phi_0 being the null value, is then calculated as the following (standard normal distribution evaluated to calculate p-value):

z = \frac{ln(\phi) - ln(\phi_0)}{se(ln(\phi))}

The confidence interval can then be calculated as the following:

\phi_{lower} = \phi \cdot e^{-z_{\alpha} \cdot se(ln(\phi))}

\phi_{upper} = \phi \cdot e^{z_{\alpha} \cdot se(ln(\phi))}

Odds Ratio

The ratio between proportions test is based on the following calculation: (p1/q1) / (p2/q2)

OR = \frac{p_1}{1-p_1} / \frac{p_2}{1-p_2}

The standard error of ln(OR) is calculated as the following:

se(ln(OR)) = \sqrt{\frac{1}{n_1 \cdot p_1 + 0.5} + \frac{1}{n_1 \cdot (1-p_1) + 0.5} + \frac{1}{n_2 \cdot p_2 + 0.5} + \frac{1}{n_2 \cdot (1-p_2) + 0.5} }

The z-test, with OR_0 being the null value, is then calculated as the following (standard normal distribution evaluated to calculate p-value):

z = \frac{ln(OR) - ln(OR_0)}{se(ln(OR))}

The confidence interval can then be calculated as the following:

OR_{lower},OR_{upper} = exp(ln(OR) \pm z_{\alpha} \cdot se(ln(OR)))

Value

An S3 object of the class htest.

References

Gart, J. J., & Nam, J. M. (1988). Approximate interval estimation of the ratio of binomial parameters: a review and corrections for skewness. Biometrics, 323-338.

Tunes da Silva, G., Logan, B. R., & Klein, J. P. (2008). Methods for Equivalence and Noninferiority Testing. Biology of Blood Marrow Transplant, 15(1 Suppl), 120-127.

Yin, G. (2012). Clinical Trial Design: Bayesian and Frequentist Adaptive Methods. Hoboken, New Jersey: John Wiley & Sons, Inc.


TOSTER documentation built on May 29, 2024, 9:57 a.m.