# 1. Closed form planner under random predictors (the typical case).
# Sample size sufficient for the expected CI width on rho^2 to be .10.
ss_aipe_R2(population_R2 = .50, conf_level = .95, width = .10,
which_width = "Full", p = 5, random_predictors = TRUE)
# 2. The same target under fixed predictors (planned dosing levels,
# factorial covariates, and the like) needs a smaller N, since fixed
# predictors contribute no sampling variability of their own.
ss_aipe_R2(population_R2 = .50, conf_level = .95, width = .10,
which_width = "Full", p = 5, random_predictors = FALSE)
# 3. An assurance of .85, so that the realized width is no larger than the
# target in 85 percent of replications rather than only on average,
# needs a larger N than the expected width plan in (1).
ss_aipe_R2(population_R2 = .50, conf_level = .95, width = .10,
which_width = "Full", p = 5, assurance = .85,
random_predictors = TRUE)
# 4. verify_ss = TRUE follows the closed form approximation with an a
# priori Monte Carlo simulation of the realized width, starting from
# the closed form answer and returning the sample size the simulation
# settles on, which is what a plan meant to be defended deserves. The
# coarse search runs g replications per candidate N and the final pass
# runs G; the small counts here keep the example quick, and a reported
# plan deserves the defaults of g = 500 and G = 10000.
set.seed(113)
ss_aipe_R2(population_R2 = .50, conf_level = .95, width = .10,
which_width = "Full", p = 5, random_predictors = TRUE,
verify_ss = TRUE, g = 10, G = 30)
Run the code above in your browser using DataLab