binom_ci: Compute Binomial Confidence Intervals

View source: R/binom_ci.R

binom_ciR Documentation

Compute Binomial Confidence Intervals

Description

A wrapper around DescTools::BinomCI to calculate confidence intervals for binomial proportions. This function formats the output into a tibble and optionally formats percentages.

Usage

binom_ci(
  x,
  n,
  conf_level = 0.95,
  sides = c("two.sided", "left", "right"),
  method = c("wilson", "wald", "waldcc", "agresti-coull", "jeffreys", "modified wilson",
    "wilsoncc", "modified jeffreys", "clopper-pearson", "arcsine", "logit", "witting",
    "pratt", "midp", "lik", "blaker"),
  rand = 123,
  tol = 1e-05,
  std_est = TRUE,
  formatted = FALSE,
  accuracy = 0.1
)

Arguments

x

Numeric. The number of successes.

n

Numeric. The number of trials.

conf_level

Numeric. Confidence level for the interval, defaults to 0.95.

sides

Character. Specifies the side of the confidence interval. Must be one of "two.sided" (default), "left", or "right". Only the first value is used if multiple are provided.

method

Character. The method used to compute the confidence interval. This can be one of "wilson" (default), "wald", "waldcc", "agresti-coull", "jeffreys", "modified wilson", "wilsoncc", "modified jeffreys", "clopper-pearson", "arcsine", "logit", "witting", "pratt", "midp", "lik", or "blaker". Abbreviations are accepted. Only the first value is used if multiple are provided.

rand

Numeric. Seed for the random number generator. Used for certain methods.

tol

Numeric. Tolerance for the "blaker" method.

std_est

Logical. If TRUE (default), returns the standard point estimator for the proportion (x/n). If FALSE, returns the method-specific point estimate.

formatted

Logical. If TRUE, formats the confidence intervals and point estimate as percentages. Defaults to FALSE.

accuracy

Numeric. The rounding accuracy for formatted percentages. Defaults to 0.1.

Value

A tibble with the following columns:

  • percentage: The point estimate of the proportion.

  • lower_ci: The lower bound of the confidence interval.

  • upper_ci: The upper bound of the confidence interval. If formatted = TRUE, these values are formatted as percentages.

Examples

# Compute a Wilson confidence interval
binom_ci(x = 25, n = 100, method = "wilson")

# Compute a Clopper-Pearson confidence interval, formatted as percentages
binom_ci(x = 25, n = 100, method = "clopper-pearson", formatted = TRUE)


emilelatour/lamisc documentation built on March 29, 2025, 1:23 p.m.