sim_longitudinal_meta: Simulate a Longitudinal Meta-Analytic Dataset

View source: R/sim_longitudinal_meta.R

sim_longitudinal_metaR Documentation

Simulate a Longitudinal Meta-Analytic Dataset

Description

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.

Usage

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
)

Arguments

k

Number of studies. Default 20.

times

Numeric vector of follow-up time points. Default c(0, 6, 12, 24).

mu

Named numeric vector of true effects at each time point, or a single value (recycled). Default 0.4.

tau

Between-study SD. Default 0.2.

v_range

Two-element vector for the uniform sampling variance range. Default c(0.02, 0.12).

missing_prop

Proportion of study x time combinations to set missing (simulates unbalanced follow-up). Default 0.0.

add_covariates

Logical. If TRUE, adds study-level covariates pub_year, quality, and n for use with ml_benchmark(). Default TRUE.

seed

Random seed. Default NULL.

Details

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.

Value

A data.frame in long format with columns:

study

Study identifier (character).

time

Follow-up time.

yi

Observed effect size.

vi

Sampling variance.

pub_year, quality, n

Study-level covariates (if add_covariates = TRUE).

Examples

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)



metaLong documentation built on March 31, 2026, 1:07 a.m.