prec_prop: Sample size or precision for a proportion

View source: R/descriptive_stats.R

prec_propR Documentation

Sample size or precision for a proportion

Description

prec_prop returns the sample size or the precision for the provided proportion.

Usage

prec_prop(
  p,
  n = NULL,
  conf.width = NULL,
  conf.level = 0.95,
  method = c("wilson", "agresti-coull", "exact", "wald"),
  ...
)

Arguments

p

proportion.

n

number of observations.

conf.width

precision (the full width of the confidence interval).

conf.level

confidence level.

method

The method to use to calculate precision. Exactly one method may be provided. Methods can be abbreviated.

...

other arguments to uniroot (e.g. tol).

Details

Exactly one of the parameters n or conf.width must be passed as NULL, and that parameter is determined from the other.

The wilson, agresti-coull, exact, and wald method are implemented. The wilson method is suggested for small n (< 40), and the agresti-coull method is suggested for larger n (see reference). The wald method is not suggested, but provided due to its widely distributed use.

uniroot is used to solve n for the agresti-coull, wilson, and exact methods. Agresti-coull can be abbreviated by ac.

Value

Object of class "presize", a list of arguments (including the computed one) augmented with method and note elements. In the wilson and agresti-coull formula, the p from which the confidence interval is calculated is adjusted by a term (i.e. p + term \pm ci). This adjusted p is returned in padj.

References

Brown LD, Cai TT, DasGupta A (2001) Interval Estimation for a Binomial Proportion, Statistical Science, 16:2, 101-117, doi: 10.1214/ss/1009213286

See Also

binom.test, binom.confint in package binom, and binconf in package Hmisc

Examples

# CI width for 15\% with 50 participants
prec_prop(0.15, n = 50)
# number of participants for 15\% with a CI width of 0.2
prec_prop(0.15, conf.width = 0.2)
# confidence interval width for a range of scenarios between 10 and 90\% with
#  100 participants via the wilson method
prec_prop(p = 1:9 / 10, n = 100, method = "wilson")
# number of participants for a range of scenarios between 10 and 90\% with
#  a CI of 0.192 via the wilson method
prec_prop(p = 1:9 / 10, conf.width = .192, method = "wilson")

presize documentation built on March 7, 2023, 8:28 p.m.