Learn R Programming

genpwr

The genpwr package for R (>3.5.1) performs power and sample size calculations for genetic association studies and allows for mis-specification of the genetic model. Calculations can be performed for binary (case/control) and continuous outcomes. Power and sample size calculations are possible for genetic effects as well as gene by environment interactions.

Example

To calculate power to detect an odds ratio of 2 for a 1:1 case control study with 2,000 subjects, assuming an alpha of 0.05, at minor allele frequencies of 0.1, 0.2, and 0.3:

library(genpwr)
#> Loading required package: ggplot2
#> Loading required package: nleqslv
#> Loading required package: MASS

genpwr.calc(calc = "power", model = "logistic", N = 2000, OR = 2,
            Alpha = 0.05, MAF = c(0.1,0.2,0.3), Case.Rate = 0.5)
#>     Test.Model True.Model MAF OR N_total N_cases N_controls Case.Rate
#> 1     Dominant   Dominant 0.1  2    2000    1000       1000       0.5
#> 3     Dominant   Additive 0.1  2    2000    1000       1000       0.5
#> 5     Dominant  Recessive 0.1  2    2000    1000       1000       0.5
#> 7     Dominant   Dominant 0.2  2    2000    1000       1000       0.5
#> 9     Dominant   Additive 0.2  2    2000    1000       1000       0.5
#> 11    Dominant  Recessive 0.2  2    2000    1000       1000       0.5
#> 13    Dominant   Dominant 0.3  2    2000    1000       1000       0.5
#> 15    Dominant   Additive 0.3  2    2000    1000       1000       0.5
#> 17    Dominant  Recessive 0.3  2    2000    1000       1000       0.5
#> 12   Recessive   Dominant 0.1  2    2000    1000       1000       0.5
#> 31   Recessive   Additive 0.1  2    2000    1000       1000       0.5
#> 51   Recessive  Recessive 0.1  2    2000    1000       1000       0.5
#> 71   Recessive   Dominant 0.2  2    2000    1000       1000       0.5
#> 91   Recessive   Additive 0.2  2    2000    1000       1000       0.5
#> 111  Recessive  Recessive 0.2  2    2000    1000       1000       0.5
#> 131  Recessive   Dominant 0.3  2    2000    1000       1000       0.5
#> 151  Recessive   Additive 0.3  2    2000    1000       1000       0.5
#> 171  Recessive  Recessive 0.3  2    2000    1000       1000       0.5
#> 14    Additive   Dominant 0.1  2    2000    1000       1000       0.5
#> 32    Additive   Additive 0.1  2    2000    1000       1000       0.5
#> 52    Additive  Recessive 0.1  2    2000    1000       1000       0.5
#> 72    Additive   Dominant 0.2  2    2000    1000       1000       0.5
#> 92    Additive   Additive 0.2  2    2000    1000       1000       0.5
#> 112   Additive  Recessive 0.2  2    2000    1000       1000       0.5
#> 132   Additive   Dominant 0.3  2    2000    1000       1000       0.5
#> 152   Additive   Additive 0.3  2    2000    1000       1000       0.5
#> 172   Additive  Recessive 0.3  2    2000    1000       1000       0.5
#> 16         2df   Dominant 0.1  2    2000    1000       1000       0.5
#> 33         2df   Additive 0.1  2    2000    1000       1000       0.5
#> 53         2df  Recessive 0.1  2    2000    1000       1000       0.5
#> 73         2df   Dominant 0.2  2    2000    1000       1000       0.5
#> 93         2df   Additive 0.2  2    2000    1000       1000       0.5
#> 113        2df  Recessive 0.2  2    2000    1000       1000       0.5
#> 133        2df   Dominant 0.3  2    2000    1000       1000       0.5
#> 153        2df   Additive 0.3  2    2000    1000       1000       0.5
#> 173        2df  Recessive 0.3  2    2000    1000       1000       0.5
#>     Power_at_Alpha_0.05
#> 1            0.99997130
#> 3            0.99999117
#> 5            0.06094645
#> 7            0.99999997
#> 9            1.00000000
#> 11           0.12562959
#> 13           0.99999999
#> 15           1.00000000
#> 17           0.26400143
#> 12           0.23736708
#> 31           0.72802319
#> 51           0.32261174
#> 71           0.51913618
#> 91           0.99712300
#> 111          0.84110046
#> 131          0.65907220
#> 151          0.99999669
#> 171          0.99128361
#> 14           0.99994745
#> 32           0.99999535
#> 52           0.09704782
#> 72           0.99999973
#> 92           1.00000000
#> 112          0.39542984
#> 132          0.99999976
#> 152          1.00000000
#> 172          0.83339405
#> 16           0.99987562
#> 33           0.99997633
#> 53           0.24913314
#> 73           0.99999976
#> 93           1.00000000
#> 113          0.75849311
#> 133          0.99999996
#> 153          1.00000000
#> 173          0.97950882

"The return object contains information about power for additive, dominant, recessive, and 2df / genotypic tests of association, assuming various true underlying genetic effects (additive, dominant, recessive). "

Installation instructions

To install genpwr, perform the following steps:

  • Install R version 3.5.1 or higher by following the instructions at https://www.R-project.org
  • From the R environment, install and load the "genpwr" package:
install.packages("genpwr")
  • Load the library
library(genpwr)

Demo

Install the genpwr package as described above.

Run the genpwr demo program

demo(genpwr_demo)

Copy Link

Version

Install

install.packages('genpwr')

Monthly Downloads

377

Version

1.0.4

License

GPL-3

Maintainer

Camille Moore

Last Published

March 31st, 2021

Functions in genpwr (1.0.4)

additive.ll.linear

Function to Calculate Additive Log Likelihood for a Linear Regression Model
X_mat_returner

Function to output X matrices used in calculation of MLE's for linear outcome with logistic environment interaction
as.numeric2

Function to convert to numeric with scientific notation containing the "." character
add.or.function

Additive Model Function
calc.like.linear

Function to Calculate Log Likelihood for a Linear Regression Model
calc.like.linear.log.envir.interaction

Function to calculate the standard deviation of y given x for linear models with logistic environment interaction
add.fun.t

Function to Calculate t matrix for logistic outcome with binary environment interaction in additive model
X_mat_returner_lle

Function to output X matrices used in calculation of MLE's for linear outcome with linear environment interaction
calc.like

Function to Calculate Log Likelihood for a Logistic Regression Model
df2.ll

Function to Calculate 2df Log Likelihood for a Logistic Regression Model
logistic.mles

Function to calculate MLE's for logistic models
linear.mles

Function to calculate MLE's for linear models
es.calc.linear

Function to Calculate Effect Size for Linear Models
find.prob.rec

Recessive probability finding function
df2.ll.linear

Function to Calculate 2 Degree of Freedom Log Likelihood for a Linear Regression Model
genpwr.calc

Function to Calculate Power for Linear Models with logistic environment interaction
logit

Logit Function
dominant.ll

Function to Calculate Dominant Log Likelihood for a Logistic Regression Model
dominant.ll.linear

Function to Calculate Dominant Log Likelihood for a Linear Regression Model
dom.fun.t

Function to Calculate t matrix for logistic outcome with binary environment interaction in dominant model
or_calc

Odds ratio calculation
integrand_funct_case

Function to generate integrand for mle for cases
null.ll

Function to Calculate Null Log Likelihood for a Logistic Regression Model
power.calc

Function to Calculate Power
recessive.ll

Function to Calculate Recessive Log Likelihood for a Logistic Regression Model
integrand_funct_control

Function to generate integrand for mle for controls
ncp.search

Function to Determine Non-Centrality Parameter of the Chi-squared distribution
rec.or.function

Recessive Model Function
p_vec_returner_lin_env

Function to output probability vector used in calculation of MLE's for linear outcome with linear environment interaction
ss_envir.calc.linear_outcome

Function to Calculate Power for Linear Models with logistic environment interaction
expected.linear.ll

Function to Calculate Expected Log Likelihood for a Single Genotype
expected.linear.ll.lin.env

Function to Calculate Expected Log Likelihood for a Single Genotype with linear environment interaction
power_linear_envir.calc.linear_outcome

Function to Calculate Power for Linear Models with linear environment interaction
p_vec_returner

Function to output probability vector used in calculation of MLE's for linear outcome with logistic environment interaction
power_linear_envir.calc.logistic_outcome

Function to Calculate Power for Linear Models with logistic environment interaction
power.plot

Function to Plot Power Results
power.calc.linear

Function to Calculate Power for Linear Models
linear.outcome.lin.envir.interaction.sds

Function to calculate the standard deviation of y given x for linear models with linear environment interaction
ll.ge.logistic

Function to calculate MLE's for logistic models with logistic environment interaction
dom.or.function

Dominant Model Function
linear.outcome.lin.envir.interaction.sds_reduced

Function to calculate the standard deviation of y given x for linear models with linear environment interaction
ll.ge.logistic.lin.envir

Function to output log likelihood for logistic outcome with linear environment variables
linear.mles.lin.envir.interaction

Function to calculate the standard deviation of y given x for linear models with linear environment interaction
linear.sds

Functions to Calculate Residual SD for Normal/Continuous Outcomes Function to calculate the standard deviation of y given x for linear models
linear.outcome.log.envir.interaction.sds

Function to calculate the standard deviation of y given x for linear models with logistic environment interaction
or.function.2df

2df Model Function
null.ll.linear

Function to Calculate Expected Null Log Likelihood for a Linear Regression Model
or.plot

Function to Plot Odds Ratio Results
ss_linear_envir.calc.linear_outcome

Function to Calculate Power for Linear Models with linear environment interaction
recessive.ll.linear

Function to Calculate Recessive Log Likelihood for a Linear Regression Model
ss_linear_envir.calc.logistic_outcome

Function to Calculate Sample Size for Linear Models with logistic environment interaction
zero_finder_nleqslv

Zero finder
odds_ratio_function

Odds Ratio Function
solve_a

Binomial coefficient calculation
ss.calc.linear

Function to Calculate Sample Size in Linear Models
quad_roots

Function to Solve Quadratic Equations
rec.fun.t

Function to Calculate t matrix for logistic outcome with binary environment interaction in recessive model
ss.calc

Function to Calculate Sample Size
find.prob.dom

Dominant probability finding function
linear.mles.lin.envir.interaction_reduced

Function to calculate the standard deviation of y given x for linear models with linear environment interaction for the reduced model without GxE interaction
linear.mles.log.envir.interaction

Function to calculate the standard deviation of y given x for linear models with logistic environment interaction
ll.linear.selector

Function to return log likelihood function for specified model type
ss_envir.calc

Function to Calculate Power for Logistic Models with Environment Interaction
power_envir.calc

Function to Calculate Power for Logistic Models with Environment Interaction
ss.plot

Function to Plot Sample Size Results
ll_zero_finder2

Zero finding function
power_envir.calc.linear_outcome

Function to Calculate Power for Linear Models with logistic environment interaction
additive.ll

Function to Calculate Additive Log Likelihood for a Logistic Regression Model