generate_spm: Generate longitudinal data from a shared-parameter model...

View source: R/generate_spm.R

generate_spmR Documentation

Generate longitudinal data from a shared-parameter model (SPM) with MNAR monotone dropout (continuous or binary outcomes)

Description

Generate longitudinal data from a shared-parameter model (SPM) with MNAR monotone dropout (continuous or binary outcomes)

Usage

generate_spm(
  n,
  t_vec,
  family = c("gaussian", "bernoulli"),
  alpha0,
  alpha1,
  rho,
  sigma_b,
  theta,
  beta0 = NA_real_,
  sigma_e = NA_real_
)

Arguments

n

Integer. Sample size (number of subjects).

t_vec

Numeric vector of visit times.

family

Character. Either "gaussian" for a continuous outcome or "bernoulli" for a binary outcome.

alpha0, alpha1

Numerics. Intercept and time slope in the dropout model (logit link).

rho

Numeric. Coupling between the shared random effect b_i and the dropout model; \rho \neq 0 induces MNAR.

sigma_b

Numeric (>0). Standard deviation of the subject-specific random intercept b_i \sim \mathcal{N}(0, \sigma_b^2).

theta

Numeric. Target effect:

  • family="gaussian": change at final visit _K: \theta = \beta_1 t_K (so the slope is \beta_1=\theta/t_K).

  • family="bernoulli": marginal response probability at the final visit in (0,1) (probit link).

beta0

Numeric. For family="bernoulli" only: probit intercept in \Phi(\beta_0 + \beta_1 t_k + b_i). Ignored for "gaussian".

sigma_e

Numeric (>0). For family="gaussian" only: residual SD.

Details

Outcome model (shared-parameter).

  • Gaussian: Y_{ik}\mid b_i \sim \mathcal{N}(\beta_1 t_k + b_i, \sigma_e^2), with \beta_1 = \theta/t_K.

  • Bernoulli (probit): Y_{ik}\mid b_i \sim \mathrm{Bernoulli}(\Phi(\beta_0 + \beta_1 t_k + b_i)), with \beta_1 = \{\sqrt{1+\sigma_b^2}\,\Phi^{-1}(\theta) - \beta_0\}/t_K.

Dropout model (MNAR, monotone).

\mathrm{logit}\,\Pr(R_{ik}=0 \mid R_{i,k-1}=1, b_i) = \alpha_0 + \alpha_1 t_k + \rho b_i,

and once dropout occurs (R_{ik}=0), all subsequent R_{i,k'}=0 for k'>k.

Value

A list with:

Ymat

n \times K matrix of outcomes (NA for missing).

Rmat

n \times K matrix of response indicators (1=observed, 0=missing).

dat

Long-format data.frame with columns id, time, R, Y.

Examples

set.seed(1000)
t_vec <- seq(4, 48, 4)
# Continuous outcome
out_c <- generate_spm(
  n = 50, t_vec = t_vec, family = "gaussian",
  alpha0 = -4, alpha1 = 0.05, rho = -1, sigma_b = 1,
  theta = -3.2, sigma_e = 1
)
# Binary outcome
out_b <- generate_spm(
  n = 200, t_vec = t_vec, family = "bernoulli",
  alpha0 = -4, alpha1 = 0.05, rho = -1, sigma_b = 1,
  theta = 0.4, beta0 = -2
)

BDIB documentation built on Oct. 18, 2026, 5:08 p.m.

Related to generate_spm in BDIB...