simulation_imputation: Simulate Longitudinal Data with Missingness

View source: R/simulation_imputation.R

simulation_imputationR Documentation

Simulate Longitudinal Data with Missingness

Description

Generates a dataset with longitudinal data containing missing covariates and outcomes. The function allows customization of random effects, residuals, and the alignment of covariates to simulate data under different conditions.

Usage

simulation_imputation(
  n_subject = 800,
  seed = NULL,
  nonrandeff = FALSE,
  nonresidual = FALSE,
  alligned = FALSE
)

Arguments

n_subject

Number of subjects in the dataset. Each subject has multiple observations. Default: 800.

seed

Random seed for reproducibility. Default: 123.

nonrandeff

Logical value indicating whether the random effects are non-normal. Default: FALSE.

nonresidual

Logical value indicating whether the residuals are non-normal. Default: FALSE.

alligned

Logical value indicating whether the covariates should be aligned (TRUE) or shuffled (FALSE). Default: FALSE. If it is shuffled, we will return covariate order as X1, X2, X3, X4, X5, X6, X9, X8, X7. If it is alligned, we will return covariate order as X1, X2, X3, X4, X5, X6, X7, X8, X9.

Details

This function creates longitudinal data for multiple subjects, each observed across 6 time points. Non-normal or normal random effects and residual conditions can be specified. Missing values are introduced based MAR assumption. The alignment of covariates can be customized to test different imputation scenarios.

Value

A list containing:

X_mis

Matrix of missing covariates.

Y_mis

Vector of missing outcomes.

Z

Matrix of complete random predictors.

subject_id

Vector of subject IDs.

time

Time points for each observation.

X_O

Matrix of original complete covariates (for evaluation).

Y_O

Vector of original complete outcomes (for evaluation).

See Also

Normal, Uniform, Binomial, Chisquare, GammaDist Mvnorm dmst reexports, mutate, select pivot_wider, pivot_longer, reexports, separate invlogit

Examples

simulated_data <- simulation_imputation(
  n_subject = 800,
  seed = 123,
  nonrandeff = TRUE,
  nonresidual = TRUE,
  alligned = FALSE
)

SBMTrees documentation built on April 3, 2025, 6:10 p.m.