Structural Equation Modeling (SEM)
Review when to use this method, its data requirements, implementation patterns, and interpretation guidance.
Description
A comprehensive multivariate statistical framework that combines factor analysis, path analysis, and regression to test complex networks of relationships between observed and latent variables. SEM accounts for measurement error, handles multiple dependent variables simultaneously, and evaluates both direct and indirect effects. It is widely used in psychology, social sciences, marketing, and health sciences for theory testing, scale validation, and causal inference.
Use Cases
- causal modeling
- path analysis
- mediation analysis
- confirmatory factor analysis
- longitudinal modeling
- multigroup analysis
Requirements
- Sample Size: medium (100-200), large (200+), very large (500+ for complex models)
- Missing Data: none, random (MAR), handled_via_FIML
- Data Distribution: multivariate_normal, non_normal (with robust estimators)
- Relationship Type: linear, non_linear (with constraints)
Variable Types
Dependent Variables
- continuous
- categorical (limited)
Independent Variables
- continuous
- categorical
- latent
Implementation
import semopy
model = '''
# Measurement model
eta1 =~ y1 + y2 + y3
eta2 =~ y4 + y5 + y6
# Structural model
eta2 ~ eta1 + x1 + x2
# Covariances
eta1 ~~ x1
'''
sem_model = semopy.Model(model)
sem_model.fit(data, obj='ML')
print(sem_model.inspect())
print(sem_model.calc_fit())
Documentation
library(lavaan)
model <- '
# Measurement model
eta1 =~ y1 + y2 + y3
eta2 =~ y4 + y5 + y6
# Structural model
eta2 ~ eta1 + x1 + x2
# Covariances
eta1 ~~ x1
'
fit <- sem(model, data=df, estimator="MLR")
summary(fit, standardized=TRUE, fit.measures=TRUE)
parameterEstimates(fit)
fitMeasures(fit, c("cfi", "rmsea", "srmr"))
Documentation
SEM
/MEASUREMENTMODEL
eta1 BY y1 y2 y3
eta2 BY y4 y5 y6
/STRUCTURALMODEL
eta2 ON eta1 x1 x2
eta1 WITH x1
/PRINT FIT PARAMETER
/FITMODEL COVARIANCE=YES.
Documentation
proc calis data=mydata method=fiml;
path
eta1 -> y1 y2 y3,
eta2 -> y4 y5 y6,
eta2 <- eta1 x1 x2;
pcorr eta1 x1;
fitindex on(only)=[chisq df cfi rmsea];
run;
Documentation
sem (eta1 -> y1 y2 y3) (eta2 -> y4 y5 y6) (eta2 <- eta1 x1 x2), cov(e.eta1*e.x1)
Documentation
Synthetic Data Example
Simulated dataset with 6 observed indicators (y1-y6), 2 latent factors (eta1, eta2), and 2 exogenous predictors (x1, x2) for SEM demonstration.
R Code for Data Generation and Analysis
library(lavaan)
set.seed(123)
n <- 300
# Generate exogenous variables
x1 <- rnorm(n)
x2 <- rnorm(n, 0.3*x1)
# Generate latent factors
eta1 <- 0.5*x1 + rnorm(n)
eta2 <- 0.6*eta1 + 0.3*x2 + rnorm(n)
# Generate observed indicators with measurement error
y1 <- 0.7*eta1 + rnorm(n, sd=0.6)
y2 <- 0.8*eta1 + rnorm(n, sd=0.5)
y3 <- 0.9*eta1 + rnorm(n, sd=0.4)
y4 <- 0.6*eta2 + rnorm(n, sd=0.7)
y5 <- 0.7*eta2 + rnorm(n, sd=0.6)
y6 <- 0.8*eta2 + rnorm(n, sd=0.5)
# Create dataframe
df <- data.frame(y1, y2, y3, y4, y5, y6, x1, x2)
# Check correlations
round(cor(df), 2)
# Descriptive statistics
summary(df)
Expected Analysis Results
Console Output
> summary(fit)
lavaan 0.6-12 ended normally after 35 iterations
Estimator ML
Optimization method NLMINB
Number of model parameters 15
Number of observations 300
Model Test User Model:
Test statistic 25.742
Degrees of freedom 16
P-value (Chi-square) 0.058
Parameter Estimates:
Standard errors Standard
Information Expected
Information saturated (h1) model Structured
Latent Variables:
Estimate Std.Err z-value P(>|z|)
eta1 =~
y1 0.699 0.056 12.571 0.000
y2 0.801 0.053 15.019 0.000
y3 0.902 0.051 17.549 0.000
eta2 =~
y4 0.603 0.062 9.774 0.000
y5 0.698 0.059 11.750 0.000
y6 0.797 0.057 14.045 0.000
Regressions:
Estimate Std.Err z-value P(>|z|)
eta2 ~
eta1 0.592 0.062 9.516 0.000
x1 0.102 0.058 1.759 0.079
x2 0.305 0.055 5.545 0.000
Covariances:
Estimate Std.Err z-value P(>|z|)
eta1 ~~
x1 0.503 0.063 7.984 0.000
Variances:
Estimate Std.Err z-value P(>|z|)
.y1 0.365 0.036 10.000 0.000
.y2 0.250 0.028 9.000 0.000
.y3 0.160 0.022 7.273 0.000
.y4 0.490 0.048 10.208 0.000
.y5 0.360 0.039 9.231 0.000
.y6 0.250 0.032 7.812 0.000
.eta1 0.750 0.075 10.000 0.000
.eta2 0.550 0.061 9.016 0.000
R-Square:
Estimate
y1 0.572
y2 0.720
y3 0.836
y4 0.424
y5 0.575
y6 0.718
eta2 0.450
Visualizations
Interpretation Guide
Need help interpreting the results of your Structural Equation Modeling (SEM) analysis? Our comprehensive interpretation guide explains:
- How to read and understand model outputs
- Interpreting coefficients and effect sizes correctly
- Understanding diagnostic plots and visualizations
- Common pitfalls and how to avoid them
- Making valid conclusions from your analysis