knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
ratesci is an R package to compute confidence intervals for rate (or risk) difference ('RD'), rate ratio ('RR', also known as relative risk), or odds ratio ('OR'). All three contrasts apply for binomial proportions, and the first two may also be used for the comparison of Poisson 'exposure-adjusted' incidence rates. The scoreci function incorporates 'skewness-corrected' asymptotic score ('SCAS') methods, which ensure equal-tailed coverage (or central location), in other words for a nominal 95% confidence interval, the one-sided non-coverage probability is (on average) close to 2.5% on each side. Stratified calculations are also catered for (e.g. meta-analysis, including random effects), as well as confidence intervals for the single binomial or Poisson rate, and for binomial matched pairs (with the pairbinci function). Corresponding hypothesis tests against any specified null parameter value are provided in each case. Omission of the skewness correction is also allowed, resulting in the often-recommended 'Miettinen-Nurminen' asymptotic score methods, which can have inferior one-sided coverage, especially for RR. The hypothesis test for binomial RD or RR when the skewness correction is omitted corresponds to the Farrington-Manning test.
The stratified (fixed effects) version without skewness correction produces a hypothesis test which is equivalent to the Cochran-Mantel-Haenszel (CMH) test, when MH weighting is used for RD or RR, or IVS weighting for OR, and the corresponding confidence intervals are guaranteed to be coherent with the test. In the single-stratum case, the hypothesis tests are equivalent to a Chi-squared test, and for paired proportions, a McNemar test (in both cases with extension to null hypotheses for equivalence/non-inferiority tests).
For large (single-stratum) sample sizes, the 'MOVER' methods (moverci function) improve on traditional approximate methods with respect to one-sided and two-sided coverage, particularly in the case of RR. Being based on Bayesian methods, these also allow the option to incorporate prior beliefs about the rates in each group - by default, the 'non-informative' Jeffreys priors are used. These methods are adapted from the Newcombe 'square-and-add' method, which is also included for reference.
For those wishing to achieve strictly conservative coverage, so-called 'continuity corrections' are provided as approximations to 'exact' methods. The performance of these adjustments has not been extensively evaluated, but they appear to be more successful for SCAS than for MOVER, in terms of achieving conservative coverage.
An online calculator based on this package is available here
The current official (i.e. CRAN) release can be installed within R with:
install.packages("ratesci")
The latest development version of the package can be installed with:
# install.packages("pak") pak::pak("petelaud/ratesci")
This builds the package from source based on the current version on GitHub
Below is a basic example which shows you how to request a confidence interval for the difference between proportions 5/56 - 0/29. The $call
output element shows that the default settings give an interval for the risk difference (contrast
= "RD"), for binomial proportions (distrib
= "bin"), at a 95% confidence level. Variance bias correction (bcf
) and skewness correction (skew
) are applied, continuity correction (cc
) is not. This is the skewness-corrected asymptotic score ("SCAS") confidence interval. (For Miettinen-Nurminen, use skew
= FALSE, for Gart-Nam, use bcf
= FALSE.)
library(ratesci) scoreci(x1 = 5, n1 = 56, x2 = 0, n2 = 29, precis = 4)
ratesci contains the following functions:
For comparisons of rates (contrasts RD, RR and OR):
scoreci()
: for score-based confidence intervals including SCAS, Miettinen-Nurminen and Gart-Nam, with or without stratification.scasci()
: wrapper function to compute SCAS intervals.tdasci()
: wrapper function to compute TDAS stratified intervals incorporating random effects.moverci()
: for the MOVER methods, including Newcombe and MOVER-J.moverbci()
: wrapper function to compute MOVER-B intervals.pairbinci()
: for paired binomial data, including asymptotic score and MOVER methods for RD and RR, and transformed binomial intervals for conditional OR.For single binomial or Poisson rates:
scaspci()
: non-iterative SCAS method for a single rate. For stratified calculations use scoreci()
with contrast = "p".jeffreysci()
: wrapper function to compute Jeffreys interval for a single rate (with option to incorporate prior information).rateci()
: wrapper function for selected methods for a single rate, including SCAS, Jeffreys, midp and Clopper-Pearson/Garwood.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.