Presize
Precision Based Sample Size Calculation
Install / Use
/learn @dcr-unibe-ch/PresizeREADME
presize <img src='man/figures/logo.png' align="right" width="200">
Bland (2009) recommended to
base study sizes on the width of the confidence interval rather the
power of a statistical test. The goal of presize is to provide
functions for such precision based sample size calculations. For a given
sample size, the functions will return the precision (width of the
confidence interval), and vice versa.
Installation
presize can be installed from CRAN in the usual manner:
install.packages("presize")
You can install the development version of presize with:
install.packages('presize', repos = c('https://dcr-unibe-ch.r-universe.dev', 'https://cloud.r-project.org'))
Overview
presize provides functions for
| Measure | Function | Methods available |
|---------------------------------------|------------------|--------------------------------------------------------------------------------------------------------------------------|
| Descriptive measures | | |
| Mean | prec_mean | |
| Proportion | prec_prop | Wilson, Agresti-Coull, exact, Wald (see Brown, Cai, and DasGupta 2001) |
| Rate | prec_rate | Score, variance stabilizing, exact, Wald (see Barker 2002) |
| Absolute differences | | |
| Mean difference | prec_meandiff | |
| Risk difference | prec_riskdiff | Newcombe (Newcombe 1998), Miettinen-Nurminen (Miettinen and Nurminen 1985), Agresti-Caffo (Agresti and Caffo 2000), Wald |
| Relative differences | | |
| Odds ratio | prec_or | Gart, Wolff, independence smoothed logit (see Fagerland, Lydersen, and Laake 2015) |
| Risk ratio | prec_riskratio | Koopman (Koopman 1984), Katz (Katz et al. 1978) |
| Rate ratio | prec_rateratio | Rothman (Rothman and Greenland 2018) |
| Correlation measures | | |
| Correlation coefficient | prec_cor | Pearson, Kendall, Spearman (see Bonnett and Wright 2000) |
| Intraclass correlation | prec_icc | Bonnett (2002) |
| Limit of agreement | prec_lim_agree | Bland and Altman (1986) |
| Cohen’s kappa | prec_kappa | Rotondi and Donner (2012) |
| Cronbach’s alpha | prec_cronb | Bonett and Wright (2015) |
| Diagnostic measures | | |
| Sensitivity<sup>1</sup> | prec_sens | As per prec_prop |
| Specificity<sup>1</sup> | prec_spec | As per prec_prop |
| Area under the curve | prec_auc | Hanley and McNeil (1982) |
| Negative likelihood ratio<sup>2</sup> | prec_neg_lr | Simel, Samsa, and Matchar (1991) |
| Positive likelihood ratio<sup>2</sup> | prec_pos_lr | Simel, Samsa, and Matchar (1991) |
| Generic likelihood ratio | prec_lr | Simel, Samsa, and Matchar (1991) |
<sup>1</sup> Simple wrappers for prec_prop.
<sup>2</sup> Wrappers for prec_lr with values provided via sens and
spec
Example
Suppose we want to estimate the proportion of hospital admissions with
diabetes. Diabetes has a prevalence of approximately 10% (Emerging Risk
Factors Collaboration et al. (2010)). We assume a slightly higher
proportion of diabetics, 15%, as diabetes is a risk factor for a wide
range of conditions. We want to estimate the prevalence of diabetes to
within 5% (plus/minus 2.5%). With presize, this is simple. We use the
prec_prop (precision of a proportion) function and pass our 15% and 5%
as arguments p and conf.width:
library(presize) # load the package
prec_prop(p = 0.15, conf.width = 0.05)
#> Warning in prec_prop(p = 0.15, conf.width = 0.05): more than one method was
#> chosen, 'wilson' will be used
#>
#> sample size for a proportion with Wilson confidence interval.
#>
#> p padj n conf.width conf.level lwr upr
#> 1 0.15 0.1517077 783.4897 0.05 0.95 0.1267077 0.1767077
#>
#> NOTE: padj is the adjusted proportion, from which the ci is calculated.
In the n column, we see that we would need to ask 784 (rounding 783.5
up) patients to achieve the desired CI width. Disappointingly, we also
know that we only have funds to collect the data from 600 patients. We
wonder if 600 patients would yield sufficient precision - we could also
accept a CI width of 6% (plus/minus 3%). In such a case, we can pass the
arguments p and n.
prec_prop(p = 0.15, n = 600)
#> Warning in prec_prop(p = 0.15, n = 600): more than one method was chosen,
#> 'wilson' will be used
#>
#> precision for a proportion with Wilson confidence interval.
#>
#> p padj n conf.width conf.level lwr upr
#> 1 0.15 0.1522266 600 0.05713404 0.95 0.1236596 0.1807936
#>
#> NOTE: padj is the adjusted proportion, from which the ci is calculated.
Now we see that with 600 patients, the CI would have a width of 5.7%. We are happy with this and continue planning our study with those values. All of the functions listed in Table 1 can be used similarly.
We can also look at a range of scenarios simulatenously by passing a vector to one of the arguments, which could be used to create something analogous to a power curve:
prec_prop(p = 0.15, n = seq(600, 800, 50))
#> Warning in prec_prop(p = 0.15, n = seq(600, 800, 50)): more than one method was
#> chosen, 'wilson' will be used
#>
#> precision for a proportion with Wilson confidence interval.
#>
#> p padj n conf.width conf.level lwr upr
#> 1 0.15 0.1522266 600 0.05713404 0.95 0.1236596 0.1807936
#> 2 0.15 0.1520563 650 0.05489329 0.95 0.1246097 0.1795030
#> 3 0.15 0.1519102 700 0.05289705 0.95 0.1254617 0.1783588
#> 4 0.15 0.1517835 750 0.05110386 0.95 0.1262316 0.1773355
#> 5 0.15 0.1516726 800 0.04948148 0.95 0.1269319 0.1764133
#>
#> NOTE: padj is the adjusted proportion, from which the ci is calculated.
Shiny app
An online interactive version of the package is available
here. The app can also be launched
locally via launch_presize_app() in RStudio.
Getting help
The package website, including more details on the functions, can be found here.
If you have a question, feel free to make a thread on the discussion page.
Related Skills
node-connect
347.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
