| define_design | R Documentation |
This is the primary setup function for any power simulation in PowRPriori.
It creates a special PowRPriori_design object that contains all the necessary
information about the variables, the hierarchical structure, and the sample size
of a planned study.
define_design(sample_size, between = NULL, within = NULL)
sample_size |
A named list specifying the building blocks and dimensions of the
planned study sample (e.g. |
between |
A list of between-subject variables. These are variables where a given unit is assigned to exactly one level of the variable (e.g., participants or entire clusters being assigned to either an intervention or a control group). |
within |
A list of within-subject variables. These are variables where all levels are observed within the same unit (e.g., repeated pre- and post-measurements within participants). |
Variable Specification:
Variables can be specified in different formats depending on their scale:
Nominal variables (e.g. a group variable with levels "control" and "treatment")
can be specified as factors (group = factor(c("control", "treatment"))) or
as character vectors (group = c("control", "treatment")), which are automatically
converted to factors. Continuous variables can be specified via their expected mean
and standard deviation (test_score = list(mean = 10, sd = 5)). Additionally,
variables can be defined as fixed numerical vectors (predictor = 1:4).
Assignment of Variables:
By default, if between variables are specified directly as a simple list
(e.g., between = list(treatment = c("A", "B"))), they are randomized at the
lowest level of the design (individual assignment).
If a between variable should be assigned at a higher cluster level
(e.g., cluster-randomization at the class level), it must be wrapped in a named list
corresponding to that specific analysis unit. You do not need to mimic the full hierarchical
structure of your design here (e.g., no need to write school = list(class = list(...))).
Simply wrap the predictor in a single list named after the exact cluster level it belongs to
(see the nested design example below).
within variables, on the other hand, are always crossed with the level-1
analysis units, effectively creating repeated measures for the lowest level.
For a full tutorial and more complex design structures, see the package vignette:
vignette("Workflow-Example", package = "PowRPriori").
A PowRPriori_design object containing the parsed design specifications.
# Simple 2x2 mixed design
simple_design <- define_design(
sample_size = list(subject = 20),
between = list(group = c("Control", "Treatment")),
within = list(time = c("pre", "post"))
)
# A nested (cluster-randomized) design where the intervention
# is assigned at the class level.
nested_design <- define_design(
sample_size = list(class = 10,
pupil = 20),
between = list(
class = list(intervention = c("yes", "no")),
pupil = list(support = c("yes", "no"))
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.