| simulate_growth | R Documentation |
Draws per-unit random growth coefficients, then forms the outcome at each
measurement occasion as
(intercept + b0) + (slope + b1) * time + (quadratic + b2) * time^2 plus
normal residual noise, where b2 is present only when random_sd has
three elements. Every unit is observed at every occasion (balanced design).
simulate_growth(
n,
times,
intercept = 0,
slope = 1,
quadratic = 0,
random_sd = c(1, 0.25),
random_correlation = NULL,
residual_sd = 1,
seed = NULL,
batch = NULL
)
n |
Number of units. A single whole number of at least 2. |
times |
Measurement occasions: a finite numeric vector of at least two
unique values, used verbatim as the |
intercept, slope, quadratic |
Fixed growth coefficients, each a single
number; they default to |
random_sd |
Standard deviations for the random intercept, slope, and
optional quadratic term. A non-negative numeric vector of length 2 (the
default, |
random_correlation |
Correlation matrix for the random effects,
matching the length of |
residual_sd |
Residual standard deviation. A single positive number,
defaulting to |
seed |
Optional random seed. |
batch |
Optional single positive whole number. When given, the
simulator runs |
A long-form simulab_sim base data.frame with one row per
unit-occasion (n * length(times) rows) and columns id, time and
outcome. Rows are ordered by occasion first and unit second. A
parameters component holds one row for each of intercept, slope,
quadratic and residual_sd, with columns term and value (note that
residual_sd is a standard deviation, and that the random-effect
standard deviations are not repeated there). A random_effects component
holds one row per unit with columns id, intercept, slope and, when
random_sd has three elements, quadratic, giving each unit's deviation
from the fixed coefficients.
result <- simulate_growth(
n = 100, times = 0:4, intercept = 10, slope = 0.5, seed = 1
)
head(result)
as.data.frame(result, what = "parameters")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.