library(tidyverse)
set.seed(2026)
n <- 500
# Simulate responses to a 5-item psychological scale (e.g., Anxiety)
# Underlying latent trait (theta) drives all item responses
data_sim <- tibble(
id = 1:n,
age = sample(18:65, n, replace = TRUE),
group = sample(c("Male", "Female"), n, replace = TRUE),
# Latent trait: true anxiety level (unobserved in real life)
theta = rnorm(n, mean = 0, sd = 1)
) %>%
mutate(
# Generate 5 Likert items (1-5 scale) based on latent trait
# Each item has a loading (<U+03BB>) and unique error
item1 = round(pmin(5, pmax(1, 3 + 0.8 * theta + rnorm(n, 0, 0.5)))),
item2 = round(pmin(5, pmax(1, 3 + 0.7 * theta + rnorm(n, 0, 0.6)))),
item3 = round(pmin(5, pmax(1, 3 + 0.9 * theta + rnorm(n, 0, 0.4)))),
item4 = round(pmin(5, pmax(1, 3 + 0.6 * theta + rnorm(n, 0, 0.7)))),
item5 = round(pmin(5, pmax(1, 3 + 0.75 * theta + rnorm(n, 0, 0.55))))
)