set.seed(2025)
n4 <- 600
# ── Assign latent class membership ────────────────────────────────────────────
# 60% Green Champions, 40% Price Skeptics
true_class <- sample(c("Green Champion", "Price Skeptic"),
size = n4, replace = TRUE,
prob = c(0.60, 0.40))
# ── Define class-specific latent factor means ─────────────────────────────────
# Green Champions: high EC, high WTP, low PS
# Price Skeptics: low EC, low WTP, high PS
# Centred within class (class differences are large)
class_means <- list(
"Green Champion" = c(EC = 1.2, WTP = 1.0, PS = -1.0, GPI = 1.0),
"Price Skeptic" = c(EC = -0.8, WTP = -0.7, PS = 0.8, GPI = -0.7)
)
# ── Generate latent scores: common factor structure, different means ───────────
lam_ec <- c(0.78, 0.75, 0.80)
lam_wtp <- c(0.76, 0.80, 0.74)
lam_ps <- c(0.72, 0.75, 0.70)
lam_gpi <- c(0.80, 0.76, 0.82, 0.78)
gen_class_items <- function(n, lam, class_mean, class_labels) {
# latent scores with class-specific mean
latent <- ifelse(class_labels == "Green Champion",
rnorm(n, mean = class_mean["Green Champion"], sd = 0.8),
rnorm(n, mean = class_mean["Price Skeptic"], sd = 0.8))
sapply(lam, function(l) l * latent + sqrt(1 - l^2) * rnorm(n))
}
EC_4 <- gen_class_items(n4, lam_ec, c("Green Champion" = 1.2, "Price Skeptic" = -0.8), true_class)
WTP_4 <- gen_class_items(n4, lam_wtp, c("Green Champion" = 1.0, "Price Skeptic" = -0.7), true_class)
PS_4 <- gen_class_items(n4, lam_ps, c("Green Champion" = -1.0, "Price Skeptic" = 0.8), true_class)
GPI_4 <- gen_class_items(n4, lam_gpi, c("Green Champion" = 1.0, "Price Skeptic" = -0.7), true_class)
# ── Compute scale scores for LCA input ────────────────────────────────────────
df4 <- data.frame(
true_class = true_class,
EC_score = rowMeans(EC_4),
WTP_score = rowMeans(WTP_4),
PS_score = rowMeans(PS_4),
GPI_score = rowMeans(GPI_4)
)