https://github.com/vikjam/pwrcalc
Power calculations in R that produce results familiar to Stata users.
https://github.com/vikjam/pwrcalc
economics experimental-design statistics
Last synced: 12 months ago
JSON representation
Power calculations in R that produce results familiar to Stata users.
- Host: GitHub
- URL: https://github.com/vikjam/pwrcalc
- Owner: vikjam
- License: mit
- Created: 2016-11-02T14:44:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-06-20T05:06:52.000Z (about 1 year ago)
- Last Synced: 2025-06-20T06:20:42.541Z (about 1 year ago)
- Topics: economics, experimental-design, statistics
- Language: R
- Homepage: http://pwrcalc.readthedocs.io/
- Size: 1.62 MB
- Stars: 5
- Watchers: 2
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Power calculations in R that produce results familiar to Stata users.
[](https://travis-ci.org/vikjam/pwrcalc) [](http://pwrcalc.readthedocs.io/en/latest/?badge=latest) [](https://gitter.im/pwrcalc/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
## Quick Start
Check out the [Read the Docs](http://pwrcalc.readthedocs.io/en/latest/?badge=latest) page for more detailed information.
### Installation
Using the R package [`devtools`](https://www.rstudio.com/products/rpackages/devtools/), you can easily install `pwrcalc`.
```{r}
devtools::install_github('vikjam/pwrcalc')
```
`devtools`includes a lot of extras functionality and dependencies. Alternatively, you just want to use [`remotes`](https://github.com/r-lib/remotes).
```{r}
install.packages("remotes")
remotes::install_github('vikjam/pwrcalc')
```
If you'd prefer installing the package without `devtools` or `ghit`, you can download the [latest release](https://github.com/vikjam/pwrcalc/releases) and [install the zipped packaged](http://outmodedbonsai.sourceforge.net/InstallingLocalRPackages.html).
### Usage
Suppose we want to detect a difference of 4 between two groups (e.g., control and treatment). For example, we anticipate the control group mean being 12 and the treatment group mean being 16. In addition, suppose the standard deviation of each group is 5. We can calculate the sample size required with `pwrcalc`,
```{r}
library(pwrcalc)
twomeans(m1 = 12, m2 = 16, sd = 5)
```
which gives us the following output.
```{r}
Two-sample t-test power calculation
m1 = 12
m2 = 16
n1 = 25
n2 = 25
sig.level = 0.05
power = 0.8
alternative = two.sided
NOTE: m1 and m2 are the means of group 1 and 2, respectively.
n1 and n2 are the obs. of group 1 and 2, respectively.
```
Now suppose we're worried about correlation between clusters. Then use the `clustered` command to account for the correlation,
```{r}
twomeans(m1 = 12, m2 = 16, sd = 5) %>% clustered(obsclus = 10, rho = 0.3)
```
which tells us we'll need a larger sample to detect the same effect.
```{r}
Two-sample t-test power calculation
m1 = 12
m2 = 16
n1 (unadjusted) = 25
n2 (unadjusted) = 25
n1 (adjusted) = 93
n2 (adjusted) = 93
rho = 0.3
Avg. per cluster = 93
Min. # of clusters = 10
sig.level = 0.05
power = 0.8
alternative = two.sided
NOTE: m1 and m2 are the means of group 1 and 2, respectively.
n1 and n2 are the obs. of group 1 and 2, respectively.
```
