forked from CTU-Bern/presize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
165 lines (119 loc) · 6.93 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
output: github_document
bibliography: paper/paper.bib
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# presize <img src='man/figures/logo.png' align="right" width="200">
[![](https://www.r-pkg.org/badges/version/presize?color=green)](https://cran.r-project.org/package=presize)
`r badger::badge_custom("dev version", as.character(packageVersion("presize")), "blue", "https://github.com/CTU-Bern/presize")`
`r badger::badge_custom("shiny app", readLines("https://shiny.ctu.unibe.ch/version/presize"), "silver", "https://shiny.ctu.unibe.ch/presize")`
[![Actions Status](https://github.com/CTU-Bern/presize/workflows/R-CMD-fullcheck/badge.svg)](https://github.com/CTU-Bern/presize/actions)
[![Codecov test coverage](https://codecov.io/gh/CTU-Bern/presize/branch/master/graph/badge.svg)](https://codecov.io/gh/CTU-Bern/presize?branch=master)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.03118/status.svg)](https://doi.org/10.21105/joss.03118)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/grand-total/presize)](https://cran.r-project.org/package=presize)
[Bland (2009)](https://www.bmj.com/content/339/bmj.b3985) 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:
```{r cran-installation, eval = FALSE}
install.packages("presize")
```
You can install the development version of `presize` with:
```{r gh-installation, eval = FALSE}
install.packages('presize', repos = 'https://ctu-bern.r-universe.dev')
```
## Overview
`presize` provides functions for
Measure | Function | Methods available
-------- | ---------- | --------
**Descriptive measures** | |
Mean | `prec_mean` |
Proportion | `prec_prop` | Wilson, Agresti-Coull, exact, Wald [see @brown2001]
Rate | `prec_rate` | Score, variance stabilizing, exact, Wald [see @barker2002]
**Absolute differences** | |
Mean difference | `prec_meandiff` |
Risk difference | `prec_riskdiff` | Newcombe [@newcombe1998], Miettinen-Nurminen [@mn1985], Agresti-Caffo [@ac2000], Wald
**Relative differences** | |
Odds ratio | `prec_or` | Gart, Wolff, independence smoothed logit [see @fll2015]
Risk ratio | `prec_riskratio` | Koopman [@koopman1984], Katz [@kbap1978]
Rate ratio | `prec_rateratio` | Rothman [@rg2018]
**Correlation measures** | |
Correlation coefficient | `prec_cor` | Pearson, Kendall, Spearman [see @bw2000]
Intraclass correlation | `prec_icc` | @bonnett2002
Limit of agreement | `prec_lim_agree` | @ba1986
Cohen's kappa | `prec_kappa` | @rd2012
Cronbach’s alpha | `prec_cronb` | @bonet10
**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` | @hm1982
Negative likelilood ratio<sup>2</sup> | `preg_neg_lr` | @simel1991
Positive likelilood ratio<sup>2</sup> | `preg_pos_lr` | @simel1991
Generic likelilood ratio | `preg_lr` | @simel1991
<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% (@diab). 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`:
```{r}
library(presize) # load the package
prec_prop(p = 0.15, conf.width = 0.05)
```
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`.
```{r}
prec_prop(p = 0.15, n = 600)
```
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:
```{r}
prec_prop(p = 0.15, n = seq(600, 800, 50))
```
## Shiny app
An online interactive version of the package is available [here](https://shiny.ctu.unibe.ch/presize). The app can also be launched locally via `launch_presize_app()` in RStudio.
```{r, echo=FALSE}
knitr::include_graphics("man/figures/app.png")
```
## Getting help
The package website, including more details on the functions, can be found [here](https://ctu-bern.github.io/presize/).
If you have a question, feel free to make a thread on the [discussion](https://github.com/CTU-Bern/presize/discussions) page.
If you encounter a bug, please create an [issue](https://github.com/CTU-Bern/presize/issues).
## Contributing
Contributions to `presize` are welcome. If you have ideas, open an [issue](https://github.com/CTU-Bern/presize/issues) or a [discussion thread](https://github.com/CTU-Bern/presize/discussions) on GitHub.
If you want to contribute code, please feel free to fork the repository, make your changes and make a pull request to have them integrated into the package. New functionality should have accompanying tests and pass continuous integration. See also the [contributing guidelines](https://github.com/CTU-Bern/presize/blob/master/CONTRIBUTING.md).
## Funding
`presize` was largely developed at CTU Bern, with collaboration from CTU Basel. Funding was provided by the Swiss Clinical Trial Organisation.
```{r, echo=FALSE}
knitr::include_graphics("man/figures/SCTO_Platforms.png")
```
<!-- ![](man/fig/scto_ctu_member_cmyk.jpg) -->
## Citation [![DOI](https://joss.theoj.org/papers/10.21105/joss.03118/status.svg)](https://doi.org/10.21105/joss.03118)
If you use `presize`, please cite it in your publication as:
Haynes et al., (2021). presize: An R-package for precision-based sample size calculation in clinical research. Journal of Open Source Software, 6(60), 3118, https://doi.org/10.21105/joss.03118
### Acknowledgements
The package logo was created with [`ggplot2`](https://ggplot2.tidyverse.org/) and [`hexSticker`](https://github.com/GuangchuangYu/hexSticker) with icons from [Font Awesome](https://fontawesome.com/) (via the [emojifont package](https://github.com/GuangchuangYu/emojifont)).
## References