Giter Site home page Giter Site logo

survivalpwr's Introduction

survivalpwr

The goal of survivalpwr is to calculate power / sample size for survival models.

Installation

You can install the development version of survivalpwr with:

devtools::install_github("LucyMcGowan/survivalpwr")

Example

You can input parameters to compute power, for example here is a study with a hazard ratio of 1.5, an event probability of 0.8, and 200 participants:

library(survivalpwr)
pwr_coxph(
  hr = 1.5,
  eventprob = 0.8,
  n = 200)
#> 
#>      Cox Regression power calculation 
#> 
#>               n = 200
#>         nevents = 160
#>              hr = 1.5
#>       eventprob = 0.8
#>         rsquare = 0
#>          stddev = 0.5
#>       sig_level = 0.05
#>           power = 0.7272216
#>     alternative = two.sided

This indicates that this study is 72.7% powered to detect a hazard ratio of 1.5 with a two-sided test with a significance level of 0.05.

Or alternatively, you can enter a target power to determine the sample size / number of events needed to obtain that power:

pwr_coxph(
  hr = 1.5,
  eventprob = 0.8,
  power = 0.8
)
#> 
#>      Cox Regression power calculation 
#> 
#>               n = 238.7095
#>         nevents = 190.9676
#>              hr = 1.5
#>       eventprob = 0.8
#>         rsquare = 0
#>          stddev = 0.5
#>       sig_level = 0.05
#>           power = 0.8
#>     alternative = two.sided

This indicates that you would need 239 observations with an event probability of 0.8 (or alternatively 191 events total) to be 80% powered to detect a hazard ratio of 1.5 with a two-sided test with a significance level of 0.05.

This function also has the ability to incorporate r-squared if you Cox regression model is expected to have covariates that are explain some variation in the predictor of interest. For example, if you want to adjust for covariates that explain 15% of the variation in the predictor of interest:

pwr_coxph(
  hr = 1.5,
  eventprob = 0.8,
  power = 0.8,
  rsquare = 0.15
)
#> 
#>      Cox Regression power calculation 
#> 
#>               n = 280.8347
#>         nevents = 224.6677
#>              hr = 1.5
#>       eventprob = 0.8
#>         rsquare = 0.15
#>          stddev = 0.5
#>       sig_level = 0.05
#>           power = 0.8
#>     alternative = two.sided

You would now need 281 observations with an event probability of 0.8 (or 225 events).

survivalpwr's People

Contributors

lucymcgowan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.