| simulate_longitudinal | R Documentation |
Draws a person mean for each unit from between_covariance around
grand_means, then runs a first-order vector autoregression on the
deviations from that person mean:
y_t = mu + intercept + transition %*% (y_{t-1} - mu) + e_t, with e_t
drawn from innovation_covariance. The first burn_in occasions are
discarded so the retained occasions are near stationarity.
simulate_longitudinal(
n,
occasions,
transition,
intercept = 0,
innovation_covariance = NULL,
initial_covariance = NULL,
between_covariance = NULL,
grand_means = 0,
beeps_per_day = NULL,
burn_in = 50L,
seed = NULL,
batch = NULL
)
n |
Number of units. A single positive whole number. |
occasions |
Number of occasions retained per unit. A single whole number of at least 2. |
transition |
Lag-one coefficients as a square matrix, or as a tidy
data frame with columns |
intercept |
Variable intercepts, a scalar recycled across variables
(the default, |
innovation_covariance |
Innovation covariance matrix, or a tidy data
frame with columns |
initial_covariance |
Initial-state covariance matrix, or a tidy data
frame with columns |
between_covariance |
Between-unit covariance of person means, or a
tidy data frame with columns |
grand_means |
Population means, a scalar recycled across variables
(the default, |
beeps_per_day |
Optional number of occasions per day; |
burn_in |
Warm-up occasions generated and then discarded before
output. A single non-negative whole 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 * occasions rows) and columns id, occasion and one
per variable, plus day and beep when beeps_per_day is supplied.
Components: wide (one row per unit, one <variable>.<occasion> column
per measurement), transition, innovation_covariance and
between_covariance (tidy matrix tables with columns row, column and
coefficient or covariance), and person_means (one row per unit with
columns id and one per variable).
# `transition` is the lag-one coefficient matrix of the VAR process.
result <- simulate_longitudinal(
n = 20,
occasions = 30,
transition = matrix(c(0.5, 0.1, 0.0, 0.4), nrow = 2, byrow = TRUE),
seed = 1
)
head(result)
components(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.