Skip to contents

Simulated longitudinal data resembling the UK Millennium Cohort Study (MCS). Contains self-control trajectories from ages 3 to 17 with three latent classes, along with complex survey design features (stratification, clustering, weights).

Usage

mcs_simulated

Format

A data frame with 29,400 rows and 14 variables:

id

Individual identifier (1 to 5000)

age

Age at assessment (3, 5, 7, 11, 14, 17 years)

selfcontrol

Self-control score (continuous, higher = better)

true_class

True latent class membership (1, 2, or 3) - for validation only

stratum

Stratum indicator (1 to 4)

stratum_factor

Stratum labels: England-Advantaged, England-Disadvantaged, Scotland/Wales, Northern Ireland

cluster

Primary sampling unit (PSU) identifier (1 to 200)

weight

Sampling weight (inverse probability weight)

sex

Sex (0 = Female, 1 = Male)

sex_factor

Sex labels (Female, Male)

baseline_risk

Baseline risk score (standardized, continuous)

ses

Socioeconomic status (standardized, continuous)

delinquency

Delinquency score at age 17 (0-10, higher = more delinquent)

academic_achievement

Academic achievement score (IQ-like, mean ~100)

Source

Simulated using simulate_gmm_survey with parameters inspired by:

Moffitt, T. E. (2006). Life-course-persistent versus adolescence-limited antisocial behavior. In D. Cicchetti & D. J. Cohen (Eds.), Developmental psychopathology (2nd ed., pp. 570-598). Wiley.

The actual Millennium Cohort Study data can be accessed through the UK Data Service: https://ukdataservice.ac.uk/

Details

This dataset is designed to mimic key features of the UK Millennium Cohort Study for teaching and demonstration purposes. It contains:

Three Latent Classes:

  • Class 1 (55%): High self-control, stable trajectory

  • Class 2 (30%): Moderate self-control, improving trajectory

  • Class 3 (15%): Low self-control, declining trajectory

Survey Design:

  • Stratified by region (4 strata)

  • Clustered within PSUs (200 clusters)

  • Probability weights to adjust for unequal sampling

  • ~12% missing data (MAR mechanism)

Auxiliary Variables:

  • Delinquency and academic achievement are related to latent class

  • Useful for demonstrating R3STEP analysis

  • Sex and SES are time-invariant predictors

Important: The true_class variable is included only for validation and teaching. In real applications, true class membership is unknown and must be estimated.

Examples

if (FALSE) { # \dontrun{
# Load data
data(mcs_simulated)

# Explore structure
head(mcs_simulated)
table(mcs_simulated$true_class)

# Visualize trajectories by true class
library(ggplot2)
ggplot(mcs_simulated, aes(x = age, y = selfcontrol, group = id,
                          color = factor(true_class))) +
  geom_line(alpha = 0.2) +
  facet_wrap(~true_class) +
  theme_minimal()

# Fit 3-class model
fit <- gmm_survey(
  data = mcs_simulated,
  id = "id",
  time = "age",
  outcome = "selfcontrol",
  n_classes = 3,
  strata = "stratum",
  cluster = "cluster",
  weights = "weight",
  starts = 100,  # Use more for final analysis
  cores = 4
)

summary(fit)
plot(fit, type = "trajectories")

# Compare estimated vs true classification
table(Estimated = fit@class_assignments,
      True = mcs_simulated$true_class[!duplicated(mcs_simulated$id)])

# R3STEP analysis with distal outcomes
r3step_results <- r3step(
  gmm_object = fit,
  distal_vars = c("delinquency", "academic_achievement"),
  data = mcs_simulated[!duplicated(mcs_simulated$id), ]
)
summary(r3step_results)
} # }