View source: R/sim_longitudinal_meta.R
| sim_longitudinal_meta | R Documentation |
Generates a synthetic long-format dataset suitable for testing and
illustrating all metaLong functions. Studies contribute effect sizes at
multiple follow-up time points with within-study correlation.
sim_longitudinal_meta(
k = 20L,
times = c(0, 6, 12, 24),
mu = 0.4,
tau = 0.2,
v_range = c(0.02, 0.12),
missing_prop = 0,
add_covariates = TRUE,
seed = NULL
)
k |
Number of studies. Default |
times |
Numeric vector of follow-up time points.
Default |
mu |
Named numeric vector of true effects at each time point,
or a single value (recycled). Default |
tau |
Between-study SD. Default |
v_range |
Two-element vector for the uniform sampling variance range.
Default |
missing_prop |
Proportion of study x time combinations to set missing
(simulates unbalanced follow-up). Default |
add_covariates |
Logical. If |
seed |
Random seed. Default |
The true effect at time t for study i is
\theta_{it} = \mu_t + u_i + \epsilon_{it}
where \mu_t is a time-varying mean effect (optionally nonlinear),
u_i \sim N(0, \tau^2) is a study-level random effect, and
\epsilon_{it} \sim N(0, v_{it}) is sampling error. Within-study
correlation between time points is introduced through u_i.
A data.frame in long format with columns:
studyStudy identifier (character).
timeFollow-up time.
yiObserved effect size.
viSampling variance.
pub_year, quality, nStudy-level covariates
(if add_covariates = TRUE).
dat <- sim_longitudinal_meta(k = 10, times = c(0, 6, 12), seed = 42)
head(dat)
# Nonlinear true trajectory
mu_t <- c("0" = 0.2, "6" = 0.5, "12" = 0.4, "24" = 0.1)
dat2 <- sim_longitudinal_meta(k = 10, times = c(0, 6, 12, 24), mu = mu_t,
missing_prop = 0.1, seed = 99)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.