| power_sim | R Documentation |
This is the main function of the PowRPriori package. It iteratively simulates
datasets for increasing sample sizes to determine the required sample size
to achieve a desired level of statistical power for specific model parameters.
power_sim(
formula,
design,
test_parameter = NULL,
fixed_effects,
random_effects = NULL,
icc_specs = NULL,
overall_variance = NULL,
family = "gaussian",
adjust_p_value = "BH",
center = "auto",
power_crit = 0.8,
along = NULL,
n_start = NULL,
n_increment,
max_simulation_steps = 100,
n_issue_stop_prop = 0.2,
n_sims = 2000,
alpha = 0.05,
parallel_plan = "multisession"
)
formula |
An lme4-style model formula (e.g. |
design |
A |
test_parameter |
A character vector of the variable names to test for power.
If |
fixed_effects |
A named list of the fixed-effects coefficients. It is highly
recommended to generate this using |
random_effects |
A named, nested list specifying the standard deviations (SDs)
and (if applicable) correlations of the random effects. It is highly
recommended to generate this using |
icc_specs |
Optional. A named list of Intraclass Correlation Coefficients for
defining simple random-intercept models. Must be used with |
overall_variance |
The total variance of the outcome, required when |
family |
The model family: |
adjust_p_value |
Controls how p-values in the data simulation are adjusted when power is calculated for more than
one parameter (as specified in |
center |
Controls if the simulation should automatically center predictors. Defaults to
|
power_crit |
The desired statistical power level (e.g., 0.80 for 80%). |
along |
A string specifying the sample size variable that the power analysis should be based on. Must be present in the
|
n_start |
The starting sample size for the simulation. Defaults to |
n_increment |
The step size for increasing the sample size in each iteration. |
max_simulation_steps |
A hard stop for the simulation, limiting the number of sample size steps to prevent infinite loops. Defaults to 100 steps. |
n_issue_stop_prop |
The proportion of model issues (e.g., singular fits, non-convergence) at which the simulation will be automatically canceled. Defaults to a proportion of 20%. |
n_sims |
The number of simulations to run for each sample size step. Defaults to 2000. |
alpha |
The significance level (alpha) for the power calculation. Defaults to 0.05. |
parallel_plan |
A string specifying the |
The function supports parallel computation using future.
Simple linear models (i.e. regression models) can also be analyzed using this function. In this case, no specification of the random_effects or icc_specs
parameter is necessary.icc_specs should only be used when simulating a model containing only random intercepts and no random slopes. Refer to the
vignette for a more detailed description of the complete workflow for using this function.
An object of class PowRPriori, which is a list containing the power table,
a sample dataset, all simulation parameters, and detailed results from all runs
(coefficients and random effect estimates).
design <- define_design(
sample_size = list(subject = 20),
between = list(group = c("Control", "Treatment")),
within = list(time = c("pre", "post"))
)
fixed_effects <- list(
`(Intercept)` = 10,
groupTreatment = 2,
timepost = 1,
`groupTreatment:timepost` = 1.5
)
random_effects <- list(
subject = list(`(Intercept)` = 3),
sd_resid = 5
)
power_results <- power_sim(
formula = y ~ group * time + (1|subject),
design = design,
fixed_effects = fixed_effects,
random_effects = random_effects,
test_parameter = "groupTreatment:timepost",
center = TRUE,
n_increment = 5,
n_start = 100,
# The parameters defined in this example are to ensure low runtime.
# Adapt these parameters!
n_sims = 10,
max_simulation_steps = 1,
parallel_plan = "sequential"
)
summary(power_results)
plot_sim_model(power_results)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.