| Type: | Package |
| Title: | Comprehensive Two-Proportion Inference |
| Version: | 1.0.0 |
| Description: | Unified methods for comparing two independent or paired proportions. Provides classical, exact, score-based, non-inferiority, equivalence, effect-size, confidence-interval, and stratified procedures with standardized publication-ready output. Farrington-Manning inference is supported through established score-based methods described by Farrington and Manning (1990) <doi:10.2307/2532443> and implemented through 'ratesci', while additional established methods are provided through 'DescTools' and base R. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.2.0) |
| Imports: | DescTools (≥ 0.99.60), ratesci (≥ 1.1.0), stats |
| Suggests: | testthat (≥ 3.0.0), knitr, rmarkdown |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| URL: | https://github.com/vinodhpmd/PropTestR |
| BugReports: | https://github.com/vinodhpmd/PropTestR/issues |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-08-21 04:44:50 UTC; m |
| Author: | Vinodhkumar Obli Rajendran [aut, cre], Keerthi Aaradhana [aut] |
| Maintainer: | Vinodhkumar Obli Rajendran <vinodhkumar.rajendran@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-08-31 12:30:08 UTC |
Compare two independent proportions
Description
Provides a unified interface for common tests and confidence intervals for two independent binomial proportions.
Usage
compare_2prop(
x1,
n1,
x2,
n2,
method = "all",
alternative = c("two.sided", "less", "greater"),
margin = 0,
conf.level = 0.95
)
Arguments
x1, x2 |
Number of successes in groups 1 and 2. |
n1, n2 |
Number of observations in groups 1 and 2. |
method |
Method or methods. Use '"all"' for the full Version 1.0 set. |
alternative |
Alternative hypothesis. |
margin |
Null difference for score/Farrington-Manning/ non-inferiority procedures. |
conf.level |
Confidence level. |
Value
An object of class 'prop_compare' containing standardized results.
Examples
result <- compare_2prop(
x1 = 82,
n1 = 100,
x2 = 75,
n2 = 100,
method = c("wald", "score", "fisher")
)
print(result)
Two One-Sided Equivalence Test for Two Independent Proportions
Description
Performs a confidence-interval-based equivalence assessment for two independent binomial proportions using the Miettinen-Nurminen confidence interval.
Usage
equivalence_2prop(x1, n1, x2, n2, margin, conf.level = 0.9)
Arguments
x1 |
Number of successes in group 1. |
n1 |
Number of observations in group 1. |
x2 |
Number of successes in group 2. |
n2 |
Number of observations in group 2. |
margin |
Positive equivalence margin. |
conf.level |
Confidence level. The default is 0.90, corresponding to a two-one-sided test procedure at alpha = 0.05. |
Details
Equivalence is concluded when the confidence interval for the risk difference lies entirely within the prespecified equivalence margins.
Value
A data frame containing the observed risk difference, confidence interval, equivalence margin, equivalence decision, and method.
Farrington-Manning Test
Description
Performs a Farrington-Manning score test for comparing two independent binomial proportions when the null hypothesis specifies a non-zero difference.
Usage
farrington_manning(
x1,
n1,
x2,
n2,
margin,
alternative = "greater",
conf.level = 0.95
)
Arguments
x1 |
Number of successes in group 1. |
n1 |
Number of observations in group 1. |
x2 |
Number of successes in group 2. |
n2 |
Number of observations in group 2. |
margin |
Null difference in proportions. |
alternative |
Alternative hypothesis. One of '"two.sided"', '"less"', or '"greater"'. |
conf.level |
Confidence level for the confidence interval. |
Value
An object of class "htest" containing the
estimated difference, confidence interval, score statistic,
p-value, null difference, and alternative hypothesis.
References
Farrington CP, Manning G (1990). Test statistics and sample size formulae for comparative binomial trials with null hypothesis of non-zero risk difference or non-unity relative risk. Statistics in Medicine, 9, 1447-1454.
Examples
result <- farrington_manning(
x1 = 82,
n1 = 100,
x2 = 85,
n2 = 100,
margin = -0.10,
alternative = "greater"
)
print(result)
Compare paired proportions
Description
Performs McNemar's test for comparing two paired binary measurements. Both the asymptotic McNemar test and the exact binomial version are supported.
Usage
paired_2prop(b, c, n, method = c("mcnemar", "mcnemar_exact"))
Arguments
b |
Number of discordant pairs in which the first measurement is a success and the second measurement is a failure. |
c |
Number of discordant pairs in which the first measurement is a failure and the second measurement is a success. |
n |
Total number of paired observations. |
method |
Method used for inference. '"mcnemar"' performs the continuity-corrected asymptotic McNemar test, while '"mcnemar_exact"' performs an exact binomial test based on the discordant pairs. |
Details
The paired risk difference is calculated as
(b - c) / n. For the exact method, the p-value is
obtained from an exact binomial test conditional on the
discordant pairs, with success probability 0.5.
If there are no discordant pairs (b + c = 0), there is
no evidence of a difference between the paired proportions.
In this case, the p-value is set to 1 and the test statistic
is returned as NA.
Value
An object of class "htest" containing the test
statistic, p-value, paired difference, discordant pairs,
sample size, and contingency table.
References
McNemar Q (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika, 12, 153-157.
Examples
# Continuity-corrected McNemar test
paired_2prop(
b = 15,
c = 5,
n = 100,
method = "mcnemar"
)
# Exact McNemar test
paired_2prop(
b = 15,
c = 5,
n = 100,
method = "mcnemar_exact"
)
Plot confidence intervals from a PropTestR result
Description
Produces a confidence-interval plot for the methods contained
in a prop_compare object.
Usage
plot_prop_result(
x,
main = "Two-proportion comparison",
xlab = "Difference in proportions"
)
Arguments
x |
A |
main |
Main title of the plot. |
xlab |
Label for the x-axis. |
Value
Invisibly returns the supplied prop_compare
object.
Examples
result <- compare_2prop(
x1 = 80,
n1 = 100,
x2 = 70,
n2 = 100,
method = c("wald", "score", "miettinen_nurminen")
)
plot_prop_result(result)
Print a PropTestR two-proportion comparison
Description
Print a PropTestR two-proportion comparison
Usage
## S3 method for class 'prop_compare'
print(x, ...)
Arguments
x |
An object of class 'prop_compare'. |
... |
Additional arguments passed to 'print.data.frame'. |
Value
Invisibly returns 'x'.
Confidence interval for a difference of proportions
Description
Calculates a confidence interval for the difference between two independent binomial proportions using established confidence interval procedures.
Usage
proportion_ci(x1, n1, x2, n2, method = "mn", conf.level = 0.95)
Arguments
x1 |
Number of successes in group 1. |
n1 |
Number of observations in group 1. |
x2 |
Number of successes in group 2. |
n2 |
Number of observations in group 2. |
method |
Confidence interval method. Supported methods include '"ac"', '"wald"', '"waldcc"', '"score"', '"scorecc"', '"mn"', '"miettinen_nurminen"', '"mee"', '"blj"', '"jeffreys"', '"ha"', '"hal"', and '"jp"'. |
conf.level |
Confidence level for the interval. Must be strictly between 0 and 1. |
Value
A data frame containing the estimated difference, lower confidence limit, upper confidence limit, and method.
Examples
proportion_ci(
x1 = 80,
n1 = 100,
x2 = 70,
n2 = 100,
method = "mn"
)
Effect measures for two independent proportions
Description
Calculates the risk difference, risk ratio, and odds ratio for two independent binomial proportions.
Usage
proportion_effects(x1, n1, x2, n2, conf.level = 0.95)
Arguments
x1 |
Number of successes in group 1. |
n1 |
Number of observations in group 1. |
x2 |
Number of successes in group 2. |
n2 |
Number of observations in group 2. |
conf.level |
Confidence level for the confidence intervals. Must be strictly between 0 and 1. |
Details
The risk difference is calculated as the difference between the two observed proportions. The risk ratio is calculated as the ratio of the two observed proportions, and the odds ratio is calculated from the corresponding odds.
Confidence intervals for the risk difference are calculated using the Miettinen-Nurminen method. Confidence intervals for the risk ratio are calculated using the Koopman method when the underlying procedure is available.
Value
A data frame containing the effect measure, estimate, lower confidence limit, and upper confidence limit.
Examples
proportion_effects(
x1 = 80,
n1 = 100,
x2 = 70,
n2 = 100
)
Stratified comparison of two proportions
Description
Performs a Cochran-Mantel-Haenszel test for comparing two proportions across multiple independent strata.
Usage
stratified_2prop(x1, n1, x2, n2, strata, conf.level = 0.95)
Arguments
x1 |
Number of successes in group 1 for each stratum. |
n1 |
Number of observations in group 1 for each stratum. |
x2 |
Number of successes in group 2 for each stratum. |
n2 |
Number of observations in group 2 for each stratum. |
strata |
Character or numeric vector identifying the
strata. Its length must equal the lengths of |
conf.level |
Confidence level for the confidence interval. The default is 0.95. |
Details
Each stratum consists of a 2 x 2 table formed from the
corresponding elements of x1, n1, x2,
and n2. The Cochran-Mantel-Haenszel test is then
performed using mantelhaen.test.
The current implementation uses the Cochran-Mantel-Haenszel
procedure for testing association across strata. The
conf.level argument is retained for interface
consistency, although the confidence interval returned by
mantelhaen.test is determined by that function's
default settings in the current implementation.
Value
A list containing the Cochran-Mantel-Haenszel test method, test statistic, p-value, confidence interval, estimated common odds ratio, and the stratified contingency tables.
Examples
x1 <- c(80, 70, 90)
n1 <- c(100, 100, 100)
x2 <- c(70, 65, 85)
n2 <- c(100, 100, 100)
strata <- c("A", "B", "C")
stratified_2prop(
x1 = x1,
n1 = n1,
x2 = x2,
n2 = n2,
strata = strata
)
Summarize a PropTestR two-proportion comparison
Description
Summarize a PropTestR two-proportion comparison
Usage
## S3 method for class 'prop_compare'
summary(object, ...)
Arguments
object |
An object of class 'prop_compare'. |
... |
Additional arguments. |
Value
The results table.
Tidy a PropTestR result
Description
Extracts the standardized results table from a
prop_compare object.
Usage
tidy_prop_result(x)
Arguments
x |
A |
Value
A data frame containing the standardized comparison results.