README.md

pwrcalc

Power calculations in R that produce results familiar to Stata users.

Travis-CI Build Status Documentation Status Join the chat at https://gitter.im/pwrcalc/Lobby

Quick Start

Check out the Read the Docs page for more detailed information.

Installation

Using the R package devtools, you can easily install pwrcalc.

devtools::install_github('vikjam/pwrcalc')

devtoolsincludes a lot of extras functionality and dependencies. Alternatively, you just want to use ghit.

ghit::install_github('vikjam/pwrcalc')

If you'd prefer installing the package without devtools or ghit, you can download the latest release and install the zipped packaged.

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,

library(pwrcalc)
twomeans(m1 = 12, m2 = 16, sd = 5)

which gives us the following output.

     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,

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.

     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.


vikjam/pwrcalc documentation built on May 5, 2019, 5:55 p.m.