Simulating power in practice

Similar documents
Multiple Linear Regression: Global tests and Multiple Testing

Simulation and resampling analysis in R

Regression Analysis and Linear Regression Models

Lab 5 - Risk Analysis, Robustness, and Power

Section 2.3: Simple Linear Regression: Predictions and Inference

Introduction to hypothesis testing

Week 4: Simple Linear Regression III

Week 4: Simple Linear Regression II

Introduction to the Practice of Statistics using R: Chapter 6

Contents Cont Hypothesis testing

Regression on the trees data with R

Multiple Linear Regression

Resampling Methods. Levi Waldron, CUNY School of Public Health. July 13, 2016

36-402/608 HW #1 Solutions 1/21/2010

DS Machine Learning and Data Mining I. Alina Oprea Associate Professor, CCIS Northeastern University

Solution to Bonus Questions

Lecture 7: Linear Regression (continued)

Practice in R. 1 Sivan s practice. 2 Hetroskadasticity. January 28, (pdf version)

Practical 4: Mixed effect models

Salary 9 mo : 9 month salary for faculty member for 2004

Analysis of variance - ANOVA

Macros and ODS. SAS Programming November 6, / 89

Chapter 6: Linear Model Selection and Regularization

In this computer exercise we will work with the analysis of variance in R. We ll take a look at the following topics:

humor... May 3, / 56

STENO Introductory R-Workshop: Loading a Data Set Tommi Suvitaival, Steno Diabetes Center June 11, 2015

Estimating R 0 : Solutions

Introduction to R, Github and Gitlab

The lmekin function. Terry Therneau Mayo Clinic. May 11, 2018

Model Selection and Inference

CSSS 510: Lab 2. Introduction to Maximum Likelihood Estimation

Gelman-Hill Chapter 3

Section 3.4: Diagnostics and Transformations. Jared S. Murray The University of Texas at Austin McCombs School of Business

Introduction to Mixed Models: Multivariate Regression

610 R12 Prof Colleen F. Moore Analysis of variance for Unbalanced Between Groups designs in R For Psychology 610 University of Wisconsin--Madison

Package clusterpower

Exercise 2.23 Villanova MAT 8406 September 7, 2015

Robust Linear Regression (Passing- Bablok Median-Slope)

BIOL 458 BIOMETRY Lab 10 - Multiple Regression

Lab #13 - Resampling Methods Econ 224 October 23rd, 2018

Section 4.1: Time Series I. Jared S. Murray The University of Texas at Austin McCombs School of Business

Applied Statistics and Econometrics Lecture 6

IQR = number. summary: largest. = 2. Upper half: Q3 =

Today. Lecture 4: Last time. The EM algorithm. We examine clustering in a little more detail; we went over it a somewhat quickly last time

Statistical Analysis of Metabolomics Data. Xiuxia Du Department of Bioinformatics & Genomics University of North Carolina at Charlotte

Poisson Regression and Model Checking

Title. Description. Menu. Remarks and examples. stata.com. stata.com. PSS Control Panel

The Bootstrap and Jackknife

Package EBglmnet. January 30, 2016

Stat 4510/7510 Homework 4

Predictive Checking. Readings GH Chapter 6-8. February 8, 2017

Statistics Lab #7 ANOVA Part 2 & ANCOVA

Resources for statistical assistance. Quantitative covariates and regression analysis. Methods for predicting continuous outcomes.

Machine Learning Techniques for Data Mining

Regression Lab 1. The data set cholesterol.txt available on your thumb drive contains the following variables:

Risk Management Using R, SoSe 2013

Statistical Analysis in R Guest Lecturer: Maja Milosavljevic January 28, 2015

STAT 113: Lab 9. Colin Reimer Dawson. Last revised November 10, 2015

Monte Carlo Analysis

Among those 14 potential explanatory variables,non-dummy variables are:

9.2 Types of Errors in Hypothesis testing

ST512. Fall Quarter, Exam 1. Directions: Answer questions as directed. Please show work. For true/false questions, circle either true or false.

Variable selection is intended to select the best subset of predictors. But why bother?

Multivariate Analysis Multivariate Calibration part 2

The linear mixed model: modeling hierarchical and longitudinal data

Lecture 13: Model selection and regularization

Beta-Regression with SPSS Michael Smithson School of Psychology, The Australian National University

Math 263 Excel Assignment 3

Comparing Fitted Models with the fit.models Package

Regression III: Lab 4

Linear Modeling with Bayesian Statistics

EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression

Linear Methods for Regression and Shrinkage Methods

Lecture 20: Outliers and Influential Points

An Introduction to the Bootstrap

MS&E 226: Small Data

Statistics 202: Data Mining. c Jonathan Taylor. Outliers Based in part on slides from textbook, slides of Susan Holmes.

Cross-validation and the Bootstrap

R Programming Basics - Useful Builtin Functions for Statistics

Two-Stage Least Squares

Product Catalog. AcaStat. Software

Speeding up R code using Rcpp and foreach packages.

THE UNIVERSITY OF BRITISH COLUMBIA FORESTRY 430 and 533. Time: 50 minutes 40 Marks FRST Marks FRST 533 (extra questions)

Using Machine Learning to Optimize Storage Systems

Week 5: Multiple Linear Regression II

Slides 11: Verification and Validation Models

Getting started with simulating data in R: some helpful functions and how to use them Ariel Muldoon August 28, 2018

Lecture 3 - Object-oriented programming and statistical programming examples

A Knitr Demo. Charles J. Geyer. February 8, 2017

Machine Learning. Topic 4: Linear Regression Models

Learner Expectations UNIT 1: GRAPICAL AND NUMERIC REPRESENTATIONS OF DATA. Sept. Fathom Lab: Distributions and Best Methods of Display

Introduction to Data Science

General Factorial Models

Stat 579: More Preliminaries, Reading from Files

9.1 Random coefficients models Constructed data Consumer preference mapping of carrots... 10

Modeling and Performance Analysis with Discrete-Event Simulation

Quality Control-2 The ASTA team

Package citools. October 20, 2018

Tying Hypothesis Tests, Power, and More Together with Functions

Package GLDreg. February 28, 2017

Transcription:

Simulating power in practice Author: Nicholas G Reich This material is part of the statsteachr project Made available under the Creative Commons Attribution-ShareAlike 3.0 Unported License: http://creativecommons.org/licenses/by-sa/3.0/deed.en US

Today s Lecture What is statistical power? Why/how might we want to simulate it? An example

Refresher: statistical power Definition of statistical power The ability of a method/test to detect an effect, conditional on that effect actually existing. The probability that our test rejects the null hypothesis when the null hypothesis is not true. Or, finding a signal that is really there

Characteristics that impact power What imapct do increases in these features have on power? sample size effect size variance of outcome variance of predictors number of predictors grouped/clustered observations

Typical power curve 1.0 Effect size 0.1 0.08 0.8 0.06 0.6 Power 0.4 0.2 0.0 200 400 600 800 1000 Sample size per cluster Reich NG, Myers JA, Obeng D, Milstone AM, Perl TM. Empirical power and sample size calculations for cluster-randomized and cluster-randomized crossover studies. PLoS ONE. 2012. 7(4): e35564.

Post-hoc power calculations are controversial It is always preferable to calculate power prior to running your analysis. Better not to justify negative findings with a post-hoc power calculation! For more, see The Abuse of Power, among others.

Formula-based power calculation Many simple tests have formulas for power, these... are easy to use may require you to estimate parameters from existing data (or make up justifiable numbers to plug in) are often appropriate for simple tests assume all standard assumptions are met are only available for simple/standard tests

Simulation-based power calculation Calculating power via simulation is a tradeoff: computational complexity for customization and flexibility. Power simulations... are available for any setting where you can simulate data (not limited to simple scenarios) can be used to preserve complex correlation sturctures in predictors (resample your X s) are not assumption- or parameter-free often require more complicated coding may be computationally intensive (i.e. need a long time to run)

Example: t-test power calculation by hand T-test: comparing mean between two groups µ 1 =5,µ 2 =7 σ 2 1 = σ2 2 =5(assumeknown) n 1 = n 2 = 20 Type I error rate = α = 0.05 H 0 : µ 1 µ 2 =0 Power =1 β = Pr ( Z > 1.96 µ 1 µ 2 2σ 2 /n ) pnorm(1.96-2/sqrt(2*5/20), lower.tail = FALSE) ## [1] 0.8074197

Example: t-test power calculation black box Compare to another method, which uses numerical optimization pnorm(1.96-2/sqrt(2*5/20), lower.tail = FALSE) ## [1] 0.8074197 power.t.test(n = 20, delta = 2, sd = sqrt(5), sig.level=0.05) ## ## Two-sample t test power calculation ## ## n = 20 ## delta = 2 ## sd = 2.236068 ## sig.level = 0.05 ## power = 0.7870829 ## alternative = two.sided ## ## NOTE: n is number in *each* group

Example: t-test power calculation (graph) Evaluate power across sample sizes curve(pnorm(1.96-2/sqrt(2*5/x), lower.tail = FALSE), from=5, to=40, ylab="power", xlab="n (per group)") abline(h=.8, lty=2) power 0.3 0.5 0.7 0.9 5 10 15 20 25 30 35 40 n (per group)

Example: t-test power calculation simulated nsim <- 1000 n <- 20 mu1 <- 5 mu2 <- 7 s2 <- 5 reject <- rep(0, nsim) for(i in 1:nsim){ x <- rnorm(20, mean=mu1, sd=sqrt(s2)) y <- rnorm(20, mean=mu2, sd=sqrt(s2)) tt <- t.test(x, y) reject[i] <- tt$p.value<.05 } mean(reject) ## [1] 0.782

Power by simulation: two different flavors Option 1: generate all data from scratch will generate clean data hard to insert authentic noise: outliers, missingness, correlated predictor structure Option 2: resample predictors from a training dataset, simulate outcome preserves structure of real predictor data requires a large dataset similar to the one you will be analyzing you should not, in general, do this type of computation on the actual dataset that you are analyzing best to have a training dataset, similar to but independent from the one you will be analyzing

Power by simulation: resampling algorithm Resampled power algorithm for regression-style models Inputs: nsim; nobs, X,anxp design matrix; a simulation model y f (X θ), with associated paramters; H 0 to test; Type I error rate, α. 1. Define a zero vector r of length nsim. 2. for i in 1 : nsim do 3. Resample (with replacement) the rows of X to create X i,anewnobsxp design matrix. 4. Simulate y. 5. Fit the model, calculate test statistic for to test evidence for evaluating H 0. 6. Save r i =1ifp-value α. 7. Calculate power as 1 β = 1 nsim nsim i=1 r i. Adapted from Kleinman and Huang (2014), and Meyers et al. (2014)

Power by resampling: example You plan to do a follow-up study to the one that generated our lung dataset. You want to replicate the results that show a significant impact of smoking on the severity of disease. You don t have a lot of money to conduct the study, so you want to enroll as few participants as possible. ## ## Call: ## lm(formula = disease ~ nutrition + airqual + crowding + smoking, ## data = data) ## ## Residuals: ## Min 1Q Median 3Q Max ## -8.1297-2.1834-0.5716 1.9412 13.3260 ## ## Coefficients: ## Estimate Std. Error t value Pr(> t ) ## (Intercept) 11.863333 2.578819 4.600 1.32e-05 *** ## nutrition -0.032784 0.007954-4.122 8.09e-05 *** ## airqual 0.257883 0.026799 9.623 1.17e-15 *** ## crowding 1.111126 0.102037 10.889 < 2e-16 *** ## smoking 4.960931 1.085292 4.571 1.48e-05 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 3.644 on 94 degrees of freedom ## Multiple R-squared: 0.8664, Adjusted R-squared: 0.8607

Power by resampling: example Inputs nsim = 1000 X, taken from lung dataset. α =0.05 Simulation model: y i = β 0 + β 1 Nut i + β 2 airqual i + β 3 crowd i + β 4 smoke i + ɛ i ɛ i Normal(0,σ 2 ) parameters, θ =(β 0,...,β 4,σ 2 ) (taken from fitted model) H 0 : β 4 =0

Power by resampling: example code nsim <- 1000 nobs <- 30 b0 <- coef(mlr)[1] b1 <- coef(mlr)[2] b2 <- coef(mlr)[3] b3 <- coef(mlr)[4] b4 <- coef(mlr)[5] rej <- rep(0, nsim) for(i in 1:nsim) { tmp_idx <- sample(1:nrow(data), replace=true, size=nobs) new_data <- data[tmp_idx,] err <- rnorm(nobs, 0, s=summary(mlr)$sigma) new_data$dis <- with(new_data, b0 + b1*nutrition + b2*airqual + b3*crowding + b4*smoking + err) fm <- lm(dis ~ nutrition + airqual + crowding + smoking, data=new_data) rej[i] <- summary(fm)$coef["smoking", "Pr(> t )"] > 0.05 } (pwr <- sum(rej)/nsim) ## [1] 0.372

Power by resampling: example code So we can say that if we were to repeat this study (in a similar population) with a sample size of 30, our study would have 0.37 to detect a true relationship between smoking and disease severity.

Power by simulation: wrap-up Power analyses can be a really useful tool to explore the likelihood of your data analysis producing valuable results. Simulating power can be valuable in settings where there is no simple formula for calculating power. It is also a good exercise to try to simulate your data you learn a lot about the structure of your data in the process!