100% found this document useful (7 votes)
122 views

Power and Sample Size in R, 1st Edition Digital DOCX Download

The document is a detailed overview of the book 'Power and Sample Size in R - 1st Edition', published by CRC Press in 2025. It covers various statistical methods and calculations related to power analysis and sample size determination using R, including hypothesis testing, analysis of variance, and regression techniques. The book is structured into chapters that address different statistical concepts and methodologies, providing a comprehensive resource for researchers and statisticians.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (7 votes)
122 views

Power and Sample Size in R, 1st Edition Digital DOCX Download

The document is a detailed overview of the book 'Power and Sample Size in R - 1st Edition', published by CRC Press in 2025. It covers various statistical methods and calculations related to power analysis and sample size determination using R, including hypothesis testing, analysis of variance, and regression techniques. The book is structured into chapters that address different statistical concepts and methodologies, providing a comprehensive resource for researchers and statisticians.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Power and Sample Size in R - 1st Edition

Visit the link below to download the full version of this book:

https://medipdf.com/product/power-and-sample-size-in-r-1st-edition/

Click Download Now


Designed cover image: © Catherine M. Crespi
First edition published 2025
by CRC Press
2385 NW Executive Center Drive, Suite 320, Boca Raton FL 33431

and by CRC Press


4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN

CRC Press is an imprint of Taylor & Francis Group, LLC

© 2025 Taylor & Francis Group, LLC

Reasonable efforts have been made to publish reliable data and information, but the author and pub-
lisher cannot assume responsibility for the validity of all materials or the consequences of their use.
The authors and publishers have attempted to trace the copyright holders of all material reproduced
in this publication and apologize to copyright holders if permission to publish in this form has not
been obtained. If any copyright material has not been acknowledged please write and let us know so
we may rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information stor-
age or retrieval system, without written permission from the publishers.

For permission to photocopy or use material electronically from this work, access
www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive,
Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact mpkbook-
[email protected]

Trademark notice: Product or corporate names may be trademarks or registered trademarks and are
used only for identification and explanation without intent to infringe.

ISBN: 978-1-138-59162-2 (hbk)


ISBN: 978-1-032-94244-5 (pbk)
ISBN: 978-0-429-48878-8 (ebk)

DOI: 10.1201/9780429488788

Typeset in CMR10 font


by KnowledgeWorks Global Ltd.

Publisher’s note: This book has been prepared from camera-ready copy provided by the authors.
To my husband and children, and all of the students
who have taught me how to teach over the years.
Taylor & Francis
Taylor & Francis Group
http://taylorandfrancis.com
Contents

Preamble xi

List of Figures xiii

List of Tables xv

1 Preliminaries 1
1.1 R implementation . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Probability distributions . . . . . . . . . . . . . . . . . . . . 1
1.3 Notation for common distributions . . . . . . . . . . . . . . . 3
1.4 R functions for common distributions . . . . . . . . . . . . . 4
1.5 Symmetric property of the normal distribution . . . . . . . . 5
1.6 Standardizing a normal distribution . . . . . . . . . . . . . . 6

2 Getting started: a first calculation 7


2.1 Steps in a sample size calculation . . . . . . . . . . . . . . . 7
2.2 Hypothesis testing . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 A first calculation: one-sample z test . . . . . . . . . . . . . 12
2.4 Effect size . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.5 Minimum detectable effect size . . . . . . . . . . . . . . . . . 24
2.6 A general formula when the test statistic is normally distributed 25
2.7 R function for z tests . . . . . . . . . . . . . . . . . . . . . . 25
2.8 Sample size adjustments . . . . . . . . . . . . . . . . . . . . 27
2.9 Sensitivity analysis . . . . . . . . . . . . . . . . . . . . . . . 28
2.10 Estimating power using simulation . . . . . . . . . . . . . . . 29
2.11 Should I conduct a power analysis after my study is completed? 31

3 One or two means 33


3.1 One-sample t test . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2 Two independent samples t test . . . . . . . . . . . . . . . . 46
3.3 Relative efficiency . . . . . . . . . . . . . . . . . . . . . . . . 54
3.4 Lognormal data . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.5 Paired t test . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.6 Remarks on R functions for t tests . . . . . . . . . . . . . . . 61
3.7 Nonparametric tests of location . . . . . . . . . . . . . . . . 62

vii
viii Contents

4 Hypotheses for different study objectives 69


4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.2 Test for nonequality . . . . . . . . . . . . . . . . . . . . . . . 71
4.3 Test for superiority . . . . . . . . . . . . . . . . . . . . . . . 71
4.4 Test for noninferiority . . . . . . . . . . . . . . . . . . . . . . 73
4.5 Test for superiority by a margin . . . . . . . . . . . . . . . . 77
4.6 Test for equivalence . . . . . . . . . . . . . . . . . . . . . . . 79
4.7 Hypotheses when a lower mean corresponds to a better outcome 86
4.8 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

5 Analysis of variance for comparing means 88


5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.2 One-way analysis of variance . . . . . . . . . . . . . . . . . . 88
5.3 Two-way analysis of variance . . . . . . . . . . . . . . . . . . 100
5.4 Analysis of covariance . . . . . . . . . . . . . . . . . . . . . . 114
5.5 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 117

6 Proportions: large sample methods 118


6.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
6.2 One-sample proportion test . . . . . . . . . . . . . . . . . . . 119
6.3 Test of two independent proportions . . . . . . . . . . . . . . 124
6.4 Test for two correlated proportions . . . . . . . . . . . . . . 132

7 Exact methods for proportions 137


7.1 One proportion: exact binomial test . . . . . . . . . . . . . . 137
7.2 Two-stage designs for single arm trials . . . . . . . . . . . . 141
7.3 Two proportions: Fisher exact test . . . . . . . . . . . . . . . 143
7.4 Two correlated proportions: exact test . . . . . . . . . . . . . 145

8 Categorical variables 148


8.1 Chi-square goodness-of-fit test . . . . . . . . . . . . . . . . . 148
8.2 Chi-square test of independence . . . . . . . . . . . . . . . . 150
8.3 Chi-square test for comparing two proportions . . . . . . . . 153
8.4 Ordinal categorical responses . . . . . . . . . . . . . . . . . . 154
8.5 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 156

9 Precision and confidence intervals 157


9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.2 Confidence intervals for means . . . . . . . . . . . . . . . . . 158
9.3 Confidence intervals for proportions . . . . . . . . . . . . . . 166
9.4 Confidence intervals for relative risk . . . . . . . . . . . . . . 171
9.5 Confidence intervals for odds ratio . . . . . . . . . . . . . . . 172
9.6 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 174
Contents ix

10 Correlation and linear regression 175


10.1 Pearson correlation coefficient . . . . . . . . . . . . . . . . . 175
10.2 Simple linear regression . . . . . . . . . . . . . . . . . . . . . 179
10.3 Multiple linear regression . . . . . . . . . . . . . . . . . . . . 182

11 Generalized linear regression 193


11.1 Power for generalized linear models . . . . . . . . . . . . . . 193
11.2 Logistic regression . . . . . . . . . . . . . . . . . . . . . . . . 195
11.3 Poisson regression . . . . . . . . . . . . . . . . . . . . . . . . 200
11.4 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 202

12 Crossover studies 203


12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
12.2 2 × 2 crossover design . . . . . . . . . . . . . . . . . . . . . . 205
12.3 (2 × 2)r crossover design . . . . . . . . . . . . . . . . . . . . 209
12.4 Efficiency of crossover designs . . . . . . . . . . . . . . . . . 212
12.5 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 214

13 Multisite trials 216


13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
13.2 Multilevel data structure . . . . . . . . . . . . . . . . . . . . 216
13.3 Considerations for multisite trials . . . . . . . . . . . . . . . 217
13.4 Model for continuous outcomes . . . . . . . . . . . . . . . . . 218
13.5 Intraclass correlation coefficient . . . . . . . . . . . . . . . . 221
13.6 Power for test of average treatment effect . . . . . . . . . . . 222
13.7 Power for test of heterogeneity of treatment effect . . . . . . 230
13.8 Binary outcomes . . . . . . . . . . . . . . . . . . . . . . . . . 232
13.9 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 236

14 Cluster randomized trials: parallel designs 237


14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
14.2 Continuous outcomes . . . . . . . . . . . . . . . . . . . . . . 238
14.3 Binary outcomes . . . . . . . . . . . . . . . . . . . . . . . . . 253
14.4 Additional resources for parallel cluster randomized trials . . 260
14.5 Individually randomized group treatment trials . . . . . . . . 261
14.6 Other multilevel trial designs . . . . . . . . . . . . . . . . . . 266

15 Cluster randomized trials: longitudinal designs 269


15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
15.2 Modeling framework for continuous outcomes . . . . . . . . . 271
15.3 Parallel cluster randomized trial with baseline measurement 281
15.4 Cluster randomized crossover designs . . . . . . . . . . . . . 285
15.5 Stepped wedge designs . . . . . . . . . . . . . . . . . . . . . 291
x Contents

16 Time to event outcomes 302


16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
16.2 Concepts for time to event studies . . . . . . . . . . . . . . . 303
16.3 Logrank test . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
16.4 Tests based on the Kaplan-Meier estimator . . . . . . . . . . 310
16.5 Distributions for survival, accrual and loss to follow up . . . 312
16.6 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 315

17 Multiple primary endpoints 316


17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
17.2 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
17.3 Co-primary endpoints . . . . . . . . . . . . . . . . . . . . . . 318
17.4 Alternative primary endpoints . . . . . . . . . . . . . . . . . 324
17.5 Additional resources . . . . . . . . . . . . . . . . . . . . . . . 327

Bibliography 329

Index 349
Preamble

This book was developed out of a course on the topic of power and sample size
calculation that I teach at the UCLA Jonathan and Karin Fielding School of
Public Health in Los Angeles, California. Through developing and teaching the
course, I found that while there are some excellent reference-style textbooks on
sample size calculation, such as Chow et al. [33], textbooks that were suitable
for teaching a rigorous course or for self-learning and that were also integrated
with software were in short supply. Hence this book was written.
I have attempted to make the material in the book accessible while not
sacrificing rigor. The book assumes the reader understands basic probabil-
ity concepts such as random variables, distributions of random variables and
hypothesis testing, although there is a short refresher in Chapter 1. Most
of the book should be accessible to graduate students who have had a one-
year core sequence in statistics or biostatistics, who are the audience for the
UCLA course, as well as scientists and investigators with some understanding
of statistics. However, it is unavoidable that more statistical sophistication
is needed to understand some of the more sophisticated modeling techniques
and study designs. The material gets more challenging starting with Chapter
11 on generalized linear models.
The goal of the book is to emphasize statistical thinking about the factors
that influence power for different study designs and outcomes. Therefore the
book develops many of the mathematical formulas that lie behind sample size
and power calculations rather than simply presenting formulas. This is not
a cookbook of recipes. It is also not intended to be a complete inventory of
sample size and power methods.
The book demonstrates calculations in R using examples. Only a basic
proficiency in R is assumed. We use functions from the powertools package,
which was developed as a companion R package to this book, as well as other
packages. There are many packages for various types of power and sample size
calculations available in R, and we try to summarize available resources in
each chapter. The index includes not only concepts and topics but also the R
functions and packages mentioned in the book.
This book focuses on applications to clinical and health-related research.
However, the methods themselves can be applied in other areas. We focus
on techniques for sample size and power analysis when planning a study in
which the data will be analyzed using traditional “frequentist” methods of
statistical inference rather than, for example, Bayesian methods. Data from
most clinical studies are analyzed using traditional frequentist methods, e.g., t

xi
xii Preamble

tests, linear and logistic regression, and linear mixed models. Although there is
a lively discussion in the scientific community about the merits and demerits of
hypothesis testing (see, for example, Wasserstein and Lazar [225]), we sidestep
these issues and assume that the study data will be analyzed using hypothesis
testing or (less commonly) confidence intervals.
I am deeply indebted to the many individuals who have helped me produce
this book and the companion R package. These include Analissa Avila, Zichen
Liu, Kristen McGreevy, Phillip Sundin and Yixuan Zhou. You forever have
my gratitude.

Catherine M. Crespi
List of Figures

1.1 Normal density function and cumulative distribution function 3


1.2 Illustration of symmetric property of the standard normal dis-
tribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1 Rejection and acceptance regions and critical values for one-
and two-sided test. . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Distribution of test statistic under null and alternative hypothe-
ses for a lower-tailed z test. . . . . . . . . . . . . . . . . . . . 16
2.3 Distribution of test statistic under null and alternative hypothe-
ses for a upper-tailed z test. . . . . . . . . . . . . . . . . . . . 18
2.4 Distribution of test statistic under null and alternative hypothe-
ses for a two-tailed z test. . . . . . . . . . . . . . . . . . . . . 20
2.5 Power for two-sided, one-sample z test for range of µA values. 29

3.1 Density of noncentral t distributions for various degrees of free-


dom and noncentrality parameter values. . . . . . . . . . . . . 36
3.2 Power for lower-tailed one-sample t test. . . . . . . . . . . . . 37
3.3 Power for upper-tailed one-sample t test. . . . . . . . . . . . . 38
3.4 Factors affecting power for a one-sample t test. . . . . . . . . 40
3.5 Noncentral chi-square and F distribution. . . . . . . . . . . . 43
3.6 Central and noncentral F distributions. . . . . . . . . . . . . 44
3.7 Power as a function of allocation ratio for a two-sample t test
with equal variances. . . . . . . . . . . . . . . . . . . . . . . . 53
3.8 Power as a function of allocation ratio for a two-sample t test
with unequal variances. . . . . . . . . . . . . . . . . . . . . . 54
3.9 Relationship between the lognormal and normal distributions.
X1 , . . . , Xn are on the original scale and the log-transformed
values are Y1 = log(X1 ), . . . , Yn = log(Xn ). The median on the
original scale corresponds to the mean on the log-transformed
scale. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

4.1 Inference for test of nonequality based on confidence interval. 73


4.2 Inference for test of superiority based on confidence interval. . 74
4.3 Relationships between µR , µT , and m > 0 when a lower or
higher mean corresponds to a better outcome. . . . . . . . . . 75
4.4 Inference for test of noninferiority based on confidence interval. 76

xiii
xiv List of Figures

4.5 Inference for test of superiority by a margin based on confidence


interval. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.6 Inference for equivalence test based on confidence interval. . . 80

6.1 Variance of the sample proportion . . . . . . . . . . . . . . . 119

10.1 Power versus number of predictors for an overall F test. . . . 187

11.1 Variance inflation factor (VIF) as a function of ρ2X1 |X2 X3 ...Xp ,


2
which is the population analogue of RX 1 |X2 X3 ...Xp
, the R2 ob-
tained when X1 is regressed on X2 , . . . , Xp . . . . . . . . . . . 199

12.1 Parallel versus crossover design . . . . . . . . . . . . . . . . . 204

13.1 Data from multisite trials without and with a site-by-condition


interaction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

14.1 Simulated data from two parallel cluster randomized trials


showing the impact of variation of the cluster-level means. . . 239

15.1 Schematic representation of different cluster randomized trial


designs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
15.2 Illustration of different correlation structures for a longitudinal
cluster randomized trial . . . . . . . . . . . . . . . . . . . . . 273
15.3 Schematic representation of a standard stepped wedge design
trial with five clusters. . . . . . . . . . . . . . . . . . . . . . . 292

16.1 Depiction of accrual and loss to follow up processes for a sur-


vival study . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
16.2 Examples of survival curves in two groups . . . . . . . . . . . 304
16.3 Kaplan-Meier survival curve estimator example . . . . . . . . 305
16.4 Survival curves from Example 16.3 . . . . . . . . . . . . . . . 312
16.5 Exponential distribution functions . . . . . . . . . . . . . . . 313

17.1 Venn diagram representing co-primary versus alternative pri-


mary endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 317
17.2 Venn diagram showing impact of correlation for co-primary
endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
17.3 Venn diagram showing impact of correlation for alternative pri-
mary endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 326
List of Tables

1.1 Notation for common distributions. . . . . . . . . . . . . . . 4

2.1 The four possible outcomes of a hypothesis test. . . . . . . . 11

5.1 One-way ANOVA sources of variation table. . . . . . . . . . . 90


5.2 Multiple testing error rates . . . . . . . . . . . . . . . . . . . 97
5.3 Sources of variation table for a two-way ANOVA with only main
effects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.4 Sources of variation table for a two-way ANOVA with an inter-
action between the two factors. . . . . . . . . . . . . . . . . . 108

6.1 Data set-up and notation for two correlated proportions. . . . 133

7.1 Counts for a 2 × 2 table . . . . . . . . . . . . . . . . . . . . . 144

8.1 Set-up and notation for chi-square goodness-of-fit test . . . . 149


8.2 Notation for chi-square test of independence for an r × c table. 150
8.3 Notation for ordinal categorical response model . . . . . . . . 154

9.1 Notation for cell counts in a 2 × 2 contingency table from a


cohort or unmatched case-control study. . . . . . . . . . . . . 173

10.1 Linear regression model sources of variation table. . . . . . . 183

12.1 (2 × 2)r crossover design with r = 2 replicates. . . . . . . . . 210

14.1 Selected values of design effect . . . . . . . . . . . . . . . . . 244


14.2 Design options for trials with multilevel structure. . . . . . . 267

15.1 Summary of models for longitudinal cluster randomized trials


with a continuous outcome and their variance/correlation pa-
rameters. CAC, cluster autocorrelation; SAC, subject autocor-
relation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

17.1 Samples sizes per group for two co-primary endpoints . . . . 323
17.2 Samples sizes per group for two alternative (“at least one”)
primary endpoints using Bonferroni adjustment . . . . . . . . 326

xv
Taylor & Francis
Taylor & Francis Group
http://taylorandfrancis.com
1
Preliminaries

1.1 R implementation
This book explains power and sample size calculations for many different
study designs and outcomes and demonstrates their implementation in R. We
assume that the reader has a basic proficiency in R. The book uses functions
from the powertools package as well as other packages. To use the functions
in an R package, it is necessary to first install the package and then load it in
the current session using the library function, e.g.,
install.packages("powertools")
library(powertools)
The reader should be sure to consult the latest R documentation when us-
ing various functions and packages. To see the documentation for the function
ttest.2samp, for example, enter at the R prompt
?ttest.2samp

1.2 Probability distributions


Calculating power entails calculating a probability, namely, the probability
of rejecting the null hypothesis in favor of the alternative hypothesis when
a specified alternative is true. A sample size calculation involves finding the
number of subjects that are needed in order to achieve a desired level of
power. These calculations involve working with random variables and their
distributions. In particular, we will need to work with cumulative distribution
functions (cdfs) and quantile functions of random variables.
The probability density function (pdf) of a random variable is a func-
tion such that the area under the curve between any two points a and b is
equal to the probability that the random variable falls between a and b. The
pdf of a normally distributed random variable Y with mean µ and variance
1
σ 2 is the function f (y) = √2πσ 2
exp[− 12 ( y−µ 2
σ ) ]. A standard normal random
variable has mean 0 and variance 1. The pdf for a standard normal random
variable is commonly denoted as ϕ(·); thus ϕ(y) = √12π exp[− 12 y 2 ].

DOI: 10.1201/9780429488788-1 1

You might also like