0% found this document useful (0 votes)
155 views28 pages

SEM Analysis Using R and lavaan

Structural equation modeling (SEM) is a statistical technique used to analyze relationships between observed and latent variables. The document discusses SEM in R using two main packages: sem and lavaan. It provides examples of building single-factor and multi-factor models to assess fit using the HolzingerSwineford1939 dataset. Model fit is evaluated by examining standardized loadings and various fit indices such as CFI, TLI, RMSEA, and SRMR.

Uploaded by

sheikh Arslan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views28 pages

SEM Analysis Using R and lavaan

Structural equation modeling (SEM) is a statistical technique used to analyze relationships between observed and latent variables. The document discusses SEM in R using two main packages: sem and lavaan. It provides examples of building single-factor and multi-factor models to assess fit using the HolzingerSwineford1939 dataset. Model fit is evaluated by examining standardized loadings and various fit indices such as CFI, TLI, RMSEA, and SRMR.

Uploaded by

sheikh Arslan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Structural Equation Modeling in R

Presented By : Presented To :
ArsLaN IsHaQ (M15-18) [Link] Ahmad khaN
Introduction
Development of Western science is based on
two great achievements: the invention of the
formal logical system (in Euclidean geometry)
by the Greek philosophers, and the possibility
to find out causal relationships by systematic
experiment (during the Renaissance).
Albert Einstein
(in Pearl, 2000)
Introduction
Structural equation modeling (SEM), as a
concept, is a combination of statistical
techniques such as exploratory factor analysis
and multiple regression.
The purpose of SEM is to examine a set of
relationships between one or more
Independent Variables (IV) and one or more
Dependent Variables (DV).
Introduction
 Structural equation modeling is also known as ‘causal
modeling’ or ‘analysis of covariance structures’.
 Path analysis and confirmatory factor analysis (CFA)
are special types of SEM.
Model Constructing
 One of the most well known covariance structure
models is called LISREL (LInear Structural
RELationships) or Jöreskog- Keesling-Wiley –
model.
 LISREL is also a name of the software (Jöreskog et
al., 1979), to analyze a latent variable model.
 The other approach in this study field is Bentler-
Weeks -model (Bentler et al., 1980) and EQS –
software (Bentler, 1995).
Model Constructing
 The latest software release attempting to implement
SEM is graphical and intuitive AMOS (Arbuckle,
1997).
 AMOS has since 2000 taken LISREL’s place as a
module of a well-known statistical software package
SPSS (Statistical Package for Social Sciences).
 Also other high quality SEM programs exist, such as
Mplus (Muthén & Muthén, 2000).
– MPlus is targeted for professional users, it has only text
input mode.
Model Constructing
 In this presentation, I will use R-Language for SEM
analysis.
 All the previously mentioned approaches to SEM use
the same pattern for constructing the model:
1. model hypotheses,
2. model specification,
3. model identification and
4. model estimation.
SEM in R with different packages
 R is free, open-source, cooperatively developed
software that implements the S statistical
programming language and computing environment.
 The current capabilities of R are extensive, and it is
in wide use, especially among statisticians.
 There are two basic packages which deals to SEM in
R.

sem lavaan
Structural Equation Modeling With the
sem Package in R
 The sem package provides basic structural equation
modeling facilities in R, including the ability to fit
structural equations in observed variable models by
two-stage least squares
 To fit latent variable models by full information
maximum likelihood assuming multinormality.
 tsls and sem functions are used in the sem package.
[Link](“sem”)
libraray(sem) #The library command loads the sem package
lavaan: An R Package for Structural
Equation Modeling
 The R package lavaan has been developed to provide
applied researchers, teachers, and statisticians, a free,
fully open-source, but commercial-quality package for
latent variable modeling.
 lavaan is an acronym for latent variable analysis, and its
name reveals the long-term goal: to provide a collection
of tools that can be used to explore, estimate, and
understand a wide family of latent variable models.
 Including factor analysis, structural equation,
longitudinal, multilevel, latent class, item response, and
missing data models (Skrondal and Rabe-Hesketh 2004;
Lee 2007; Muth´en 2002).
Structural Equation Modeling with lavaan in R

One-Factor Models
We will create a one-factor model of mental test abilities using the classic
Holzinger and Swineford (1939) dataset.
SEM GOALS And Example Model
 Explore the relationship between the variables
 Confirm the structure of the developed model

IQ score

Block Digit Matrix ACT GRE


GPA
design spam reason score score
Variables in SEM
Manifest variables
Real number in data set Manifest Manifest Manifest
variable variable variable
Represented by square
Latent variables
Phenomenon measured by manifest variable
Represented by circle

Latent
variable
SET UP MODEL
Library(lavaan)
### In our version of the dataset, only 9 out of the original 26 tests are
included that has been used in many papers and books on SEM……
Data(HolzingerSwineford1939)
Build Text Speed Model
# Load the lavaan library
library(lavaan)
# Look at the Dataset
data(HolzingerSwineford1939)
head(HolzingerSwineford1939[ , 7:15])
# Define your model specification
[Link] <- 'textspeed =~ x4 + x5 + x6 + x7 + x8 + x9'
Build Political Democracy Model
# Load the lavaan library
library(lavaan)
# Look at the dataset
data( PoliticalDemocracy)
head( PoliticalDemocracy)
# Define your model specification
[Link] <- 'poldemo60 =~ y1 + y2 + y3 + y4'
MODEL ANALYSIS
 Model terms
Degree of freedom
• Determined by the number of manifest variables and
estimated values
• df = Possible Values - Estimated Values
• Possible Values = Manifest Variables * (Manifest Variables + 1) / 2

Identification:
• Include at least three manifest variables
• Create models with df > 0
• Use scaling and constraints to control df
MODEL ANALYSIS
MODEL ANALYSIS
Analyze Text Speed Model
R code for text speed model
# Load the lavaan library
library(lavaan)
# Load the dataset and define model
data(HolzingerSwineford1939)
[Link] <- 'textspeed =~ x4 + x5 + x6 + x7 + x8 + x9‘
# Analyze the model with cfa()
[Link] <- cfa (model = [Link], data =
HolzingerSwineford1939)
# Summarize the model
Summary ( [Link])
Analyze Text Speed Model
Output
Model Assessment
Standardized Loadings
Loadings – strength of the relationship of the manifest
variable(s) to the latent variable, and the standardized loadings
often easiest to interpret.
Model Assessment
Fit Indices
Model Fit – how well the data fit the specified model
 Goodness of fit indices like the Comparative Fit Index (CFI) or the
Tucker Lewis Index (TLI)
 Badness of fit indices like Root Mean Square Error of Approximation
(RMSEA) or Standardized Root Mean Square Residual (SRMR)
summary( [Link], standardized = TRUE, [Link] = TRUE)
Examine Standardized Loadings AND
EXPLORE FIT INDICES
R code for measures fit indices
library(lavaan) # Load the lavaan library
data(HolzingerSwineford1939) # Load the data and define model
[Link] <- 'textspeed =~ x4 + x5 + x6 + x7 + x8 + x9‘
# Analyze the model with cfa()
[Link] <- cfa(model = [Link], data =
HolzingerSwineford1939)
# Summarize the model for standardized loadings
summary([Link], standardized = TRUE)
# Explore the fit indices
summary([Link], [Link] = TRUE)
Multifactor model for the Holzinger &
Swineford data.
A CFA model that is often proposed for these 9
variables consists of three correlated latent variables
(or factors), each with three indicators: ˆ
A visual factor measured by 3 variables:
x1, x2 and x3, ˆ
A textual factor measured by 3 variables:
x4, x5 and x6, ˆ
A speed factor measured by 3 variables:
x7, x8 and x9.
Path diagram of the three factor model
for the Holzinger & Swineford data
Specifying a model using the lavaan
model syntax
[Link] <- 'visual =~ x1 + x2 + x3 +
textual =~ x4 + x5 + x6 +
speed =~ x7 + x8 + x9‘
We can now fit the model as follows:
fit <- cfa([Link], data = HolzingerSwineford1939)
summary(fit, [Link] = TRUE)
Results:
(CFI) 0.931 RMSEA 0.092
(TLI) 0.896 (AIC) 7517.490 (BIC) 7595.339

You might also like