simulate.latents_growth_mixture: Simulate outcomes from a growth mixture model

View source: R/growth-mixture-simulate.R

simulate.latents_growth_mixtureR Documentation

Simulate outcomes from a growth mixture model

Description

Draws new outcomes on the fitted design: each person's class from their membership probabilities, their random effects from that class's covariance, and their outcomes around their own trajectory with the class's residual variance.

Usage

## S3 method for class 'latents_growth_mixture'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

A latents_growth_mixture fit.

nsim

Number of simulated outcome vectors.

seed

NULL or an integer seed; the caller's random state is restored afterwards.

...

Unused.

Value

A base data.frame with one row per fitted row and one column per simulation, sim_1, sim_2, ...

Examples

few_students <- subset(growth_scores, student <= 60)
small_fit <- mixture_regression(score ~ wave, few_students, n_classes = 2,
                                id = "student", class_level = "group",
                                random = "intercept", seed = 1)
head(simulate(small_fit, nsim = 2, seed = 1))

# All 300 students, with random intercepts and slopes
fit <- mixture_regression(score ~ wave, growth_scores, n_classes = 3,
                          id = "student", class_level = "group",
                          random = "wave", random_covariance = "equal",
                          n_starts = 2, seed = 1)
head(simulate(fit, nsim = 2, seed = 1))


latents documentation built on Oct. 16, 2026, 5:09 p.m.