# Sample R script for sample size calculations using PowerTOST # Developed by Nathan Teuscher # January 2025 # Load PowerTOST functions library(PowerTOST) # Example 1 # 2-way crossover BE study # alpha = 0.05 # CV = 0.2 # Test/Reference = 0.95 # BE limits = 0.8 to 1.25 # Power = 0.8 # you can type ?sampleN.TOST in the console to see all of the options for this function sampleN.TOST(alpha = 0.05, targetpower = 0.8, CV = 0.2, theta0 = 0.95, theta1 = 0.8, theta2 = 1.25, design = "2x2") # +++++++++++ Equivalence test - TOST +++++++++++ # Sample size estimation # ----------------------------------------------- # Study design: 2x2 crossover # log-transformed data (multiplicative model) # # alpha = 0.05, target power = 0.8 # BE margins = 0.8 ... 1.25 # True ratio = 0.95, CV = 0.2 # # Sample size (total) # n power # 20 0.834680 # Try again with test/reference of 98% sampleN.TOST(alpha = 0.05, targetpower = 0.8, CV = 0.2, theta0 = 0.98, theta1 = 0.8, theta2 = 1.25, design = "2x2") # +++++++++++ Equivalence test - TOST +++++++++++ # Sample size estimation # ----------------------------------------------- # Study design: 2x2 crossover # log-transformed data (multiplicative model) # # alpha = 0.05, target power = 0.8 # BE margins = 0.8 ... 1.25 # True ratio = 0.98, CV = 0.2 # # Sample size (total) # n power # 16 0.817447 # Try again with CV of 30% and test/reference of 95% sampleN.TOST(alpha = 0.05, targetpower = 0.8, CV = 0.3, theta0 = 0.95, theta1 = 0.8, theta2 = 1.25, design = "2x2") # +++++++++++ Equivalence test - TOST +++++++++++ # Sample size estimation # ----------------------------------------------- # Study design: 2x2 crossover # log-transformed data (multiplicative model) # # alpha = 0.05, target power = 0.8 # BE margins = 0.8 ... 1.25 # True ratio = 0.95, CV = 0.3 # # Sample size (total) # n power # 40 0.815845 # What is power for a specific study design and sample size power.TOST(n = 16, alpha = 0.05, CV = 0.2, theta0 = 0.95, theta1 = 0.8, theta2 = 1.25, design = "2x2") # What happens if you underestimate the CV? power.TOST(n = 20, alpha = 0.05, CV = 0.3, theta0 = 0.95, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Real-life example sampleN.TOST(alpha = 0.05, targetpower = 0.8, CV = 0.23, theta0 = 0.93, theta1 = 0.8, theta2 = 1.25, design = "2x2") # +++++++++++ Equivalence test - TOST +++++++++++ # Sample size estimation # ----------------------------------------------- # Study design: 2x2 crossover # log-transformed data (multiplicative model) # # alpha = 0.05, target power = 0.8 # BE margins = 0.8 ... 1.25 # True ratio = 0.93, CV = 0.23 # # Sample size (total) # n power # 30 0.804800 # CV% could be as high as 27% # test/reference could be as low as 90% # Is 30 the right number of subjects? # Check CV of 27% power.TOST(n = 30, alpha = 0.05, CV = 0.27, theta0 = 0.93, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Check test/reference of 90% power.TOST(n = 30, alpha = 0.05, CV = 0.23, theta0 = 0.90, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Check test/reference of 90% and CV is 27% power.TOST(n = 30, alpha = 0.05, CV = 0.27, theta0 = 0.90, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Calculate sample for "worst" situation sampleN.TOST(alpha = 0.05, targetpower = 0.8, CV = 0.23, theta0 = 0.90, theta1 = 0.8, theta2 = 1.25, design = "2x2") # +++++++++++ Equivalence test - TOST +++++++++++ # Sample size estimation # ----------------------------------------------- # Study design: 2x2 crossover # log-transformed data (multiplicative model) # # alpha = 0.05, target power = 0.8 # BE margins = 0.8 ... 1.25 # True ratio = 0.9, CV = 0.23 # # Sample size (total) # n power # 48 0.804809 # Now what if we have 48 subjects in those same situations as was originally described? # Check CV of 27% power.TOST(n = 48, alpha = 0.05, CV = 0.27, theta0 = 0.93, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Check test/reference of 90% power.TOST(n = 48, alpha = 0.05, CV = 0.23, theta0 = 0.90, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Check test/reference of 90% and CV is 27% power.TOST(n = 48, alpha = 0.05, CV = 0.27, theta0 = 0.90, theta1 = 0.8, theta2 = 1.25, design = "2x2") # Parallel design example sampleN.TOST(alpha = 0.05, targetpower = 0.8, CV = 0.2, theta0 = 0.95, theta1 = 0.8, theta2 = 1.25, design = "parallel") # +++++++++++ Equivalence test - TOST +++++++++++ # Sample size estimation # ----------------------------------------------- # Study design: 2 parallel groups # log-transformed data (multiplicative model) # # alpha = 0.05, target power = 0.8 # BE margins = 0.8 ... 1.25 # True ratio = 0.95, CV = 0.2 # # Sample size (total) # n power # 36 0.809940