Nonlinear SEM with lavaan / R

Arndt Regorz, Dipl. Kfm. & M.Sc. Psychologie, 01/17/2024

This is a companion webpage to the video tutorial (YouTube) about nonlinear SEM in lavaan..


R-Code from the video tutorial

library(lavaan)

head(simulation_data, 5)

with(simulation_data, plot(IV, DV))

# 1. True Relationship

simulation_data$IV_SQ <- (simulation_data$IV)^2

true_model <- '
DV ~ IV + IV_SQ'

fit_true <- sem(model = true_model, data=simulation_data)
summary(fit_true, standardized = T)

# 2. Product Indicators in Lavaan

attach(simulation_data)
simulation_data$IV1_sq <- IV1 * IV1
simulation_data$IV2_sq <- IV2 * IV2
simulation_data$IV3_sq <- IV3 * IV3
simulation_data$IV4_sq <- IV4 * IV4
detach(simulation_data)

model_prod <- '
IV_lat =~ IV1 + IV2 + IV3 + IV4
IV_lat_sq =~ IV1_sq + IV2_sq + IV3_sq + IV4_sq
DV_lat =~ DV1 + DV2 + DV3 + DV4

IV1_sq ~~ IV1
IV2_sq ~~ IV2
IV3_sq ~~ IV3
IV4_sq ~~ IV4
IV_lat ~~ IV_lat_sq

DV_lat ~ IV_lat + IV_lat_sq
'

fit_prod <- sem(model=model_prod, data= simulation_data)
summary(fit_prod, fit.measures = T, standardized = T)