EPSY:579 R Cookbook for SEM
1
Course
2
R Exercises
3
Week4_1: Lavaan Lab 1 Path Analysis Model
3.1
Reading-In and Working With Realistic Datasets In R
3.2
Sample Covariance Matrices using the cov() function
3.3
Installing Packages
3.4
Loading Packages (Libraries) That You Have Installed
3.5
Using Lavaan For Path Models
3.5.1
PART I: Follow the set of equations we wrote in class:
3.5.2
PART II Let’s run our model!
3.5.3
Sigma Matrices
3.5.4
PART III: Summarizing Our Analysis:
3.6
Plotting SEM model
3.6.1
customize it your way
3.7
Exercise: How would you fit the model in Saunders et al. (2016)?
4
Week4_2: Lavaan Lab 2 Mediation and Indirect Effects
4.1
Reading-In and Working With Realistic Datasets In R
4.2
Using Lavaan For Mediation Models - Preacher & Hayes’s
4.3
PART I: # Follow the two equations of M (DietSE) & Y (Bulimia)
4.4
PART II Let’s run our model!
4.4.1
Label the mediation effect
4.4.2
Define a new term for the mediation effect a*b
4.5
PART III: Summarizing Our Analysis:
4.6
PART IV: Bootstrap confidence intervals
4.6.1
The default one is boot.ci.type = “perc”
4.6.2
BC (bias-corrected) confidence interval
4.7
In-Class Exercise: Use Lavaan to estimate and interpret the following model
4.8
Exercise: Eating Disorder Mediation Analysis
4.8.1
Step 1: Labeling and defining the parameters
4.8.2
Step 2: Fix all disturbance covariances at 0
4.8.3
Step 3: Define new terms for mediation effects
4.8.4
Step 4: Bootstrap confidence intervals:
4.8.5
Step 5: Print and interpret the mediation effects;
4.8.6
Plot it!
5
Week5_2: Lavaan Lab 3 Moderation and Conditional Effects
5.1
Reading-In Datasets
5.2
Interactions in Regression Using lm()
5.3
Interactions in Lavaan
5.3.1
IMPORTANT NOTE
5.3.2
Follow the equation of Y (Depression):
5.4
Visual inspection of interactions
5.5
Centering Continuous Moderator
5.6
Interactions in Lavaan (Continuous Moderator)
5.7
Simple Slopes Analysis
5.8
Visual inspection of interactions (lm approach)
5.9
JOHNSON-NEYMAN INTERVAL
5.10
Exercise: How Framing Affects Justifications for Giving or Withholding Aid to Disaster Victims
5.10.1
Data Prep
5.10.2
Moderation with a binary moderator
6
Week6_1: Lavaan Lab 4 Mediated Moderation & Moderated Mediation
6.1
PART 1: Mediated Moderation (Indirect Conditional effect)
6.1.1
Step 1: Read-in Data
6.1.2
Step 2: Create the interaction term for Moderation Analysis
6.1.3
Step 3: Write the syntax and Fit the model
6.1.4
Step 4: Bootstrap Version
6.1.5
Step 5: Effect size measures
6.2
PART 2: Moderated Mediation (Conditional Indirect effect)
6.2.1
Step 1: Product Term
6.2.2
Step 2: Write the syntax and Fit the model
6.2.3
Step 3: Bootstrap Version
6.2.4
Step 4: Simple Slopes
6.2.5
Step 5 JOHNSON-NEYMAN INTERVAL
7
Week6_2: R Lab on Disaster Dataset (Chapman and Lickel, 2016)
7.1
Data Prep
7.1.1
Scatterplot Matrix
7.1.2
p-value or bootstrapped confidence interval?
7.2
Model 1: Simple Linear Regression Model
7.3
Model 2: Simple Mediation Model
7.4
Model 3: Simple Moderation Model
7.4.1
JOHNSON-NEYMAN INTERVAL
7.5
Model 4a: Moderated Mediation Model - Path a only
7.6
Model 4b: Moderated Mediation Model - Path b only
7.7
Model 4c: Moderation & Mediation Model - Path cprime only
7.8
Model 4d: Moderated Mediation Model - Path a and cprime
7.9
Model 4e: Moderated Mediation Model - Path b and cprime
7.10
Model 4f: Moderated Mediation Model - Path a and b
7.11
Model 4g: Moderated Mediation Model - Path a, b, and cprime
7.12
Conclusions
8
Week7_1: Lavaan Lab 5 One-factor CFA Model
8.1
Data Prep
8.2
PART I: One-Factor CFA, Fixed Loading
8.2.1
Fixed Loading, AKA Marker Variable method.
8.2.2
Change marker indicator
8.3
PART II: One-Factor CFA, Fixed Factor Variance
8.3.1
Fixed Factor Method
8.4
Exercise: One-factor CFA Model
8.4.1
Fixed Loading
8.4.2
Fixed Factor
9
Week8_1: Lavaan Lab 6 Two-factor CFA Model
9.1
Data Prep
9.2
PART I: Two-Factor CFA, Fixed Loading
9.2.1
Fixed Loading, AKA Marker Variable method.
9.2.2
How well does this model fit to the data?
9.2.3
Fundamental Equation of SEM
9.2.4
Interpretion
9.2.5
Standardized solutions: Std.lv vs. Std.all
9.3
PART II: Two-Factor CFA, Fixed Factor Variance
9.3.1
Fixed Factor Method
10
Week8_2: Lavaan Lab 7 Two-factor SR Model
10.1
Data Prep
10.2
PART I: Two-Factor SR, Fixed Loading
10.2.1
Fixed Loading, AKA Marker Variable method.
10.3
PART II: Two-Factor SR, Fixed Factor Variance
10.3.1
Fixed Factor Method
10.4
PART III: Exercise (what fun!): 3-Factor SR Model
11
Week8_2: Lavaan Lab 8 Estimation Methods
11.1
PART I: Hypothetical Example
11.1.1
One-factor CFA model
11.2
PART II: ULS on the Positive Affect Example
11.3
PART III: Calculate ULS test statistic manually
11.4
PART IV: ML vs ULS vs WLS
11.4.1
ML Estimation
11.4.2
WLS Estimation
11.4.3
Compare the parameter estimates
11.5
PART V: Improper Solutions
12
Week10_2: Lavaan Lab 9 Model Fit Part I (Test Statistics)
12.1
PART I: Robust ML on the Positive Affect Example
12.1.1
Mean corrected statistic (T_M)
12.1.2
Mean and variance adjusted statistic (T_MV)
12.1.3
Yuan-Bentler test statistic (T_MLR)
12.1.4
Small sample correction - F test
12.2
PART II: Nested Model Comparison
12.2.1
One-factor model
12.2.2
Plotting
12.2.3
Comparing Nested Models
12.3
PART III: Exercises: More Nested Models
12.3.1
Exercises: Compare the base model (fixedIndTwoFacRun) to
12.3.2
Model 2: Orthogonal Factors
12.3.3
Model 3: Cross loading
12.3.4
Model 4: Correlated Unique Factors
13
Week11_1: Lavaan Lab 10 Model Fit Part II (Fit Indices)
13.1
PART I: Fit Indices
13.1.1
RMSEA
13.1.2
SRMR
13.1.3
Null Model MO
13.1.4
CFI/TLI
13.1.5
Loglikelihood
13.1.6
AIC/BIC
13.2
PART II: Exercise
13.2.1
PART I: Plot the distributions of all indicators
13.2.2
PART II: Write out the model syntax for two-factor model
13.2.3
PART III: Fit the two-factor model
13.2.4
PART IV: Interpret the chisquare statistic and fit indices
14
Week11_2: Lavaan Lab 11 Model Local Fitting and Model Modifications
14.1
PART I: Local Fit with Residuals
14.1.1
Unstandardized residuals
14.1.2
Standardized residuals
14.1.3
Normalized residuals
14.2
PART II: Modification Indices
14.2.1
Modified Model 1:
14.2.2
Modified Model 2_1:
14.2.3
Modified Model 2_2:
14.2.4
Modified Model 3:
15
Week12_1: Lavaan Lab 12 SEM for Missing Data
15.1
PART I: Generate some missing data
15.2
PART II: Visualization of missing data patterns (nice-to-have)
15.3
PART III: Build a CFA model with missing data
15.4
PART IV: Addressing missing data
15.4.1
FIML
15.4.2
Multiple Imputation
16
Week12_2: Lavaan Lab 13 SEM for Nonnormal and Categorical Data
16.1
PART I: Nonnormality Diagnosis
16.2
PART II: Robust corrections
16.3
PART III: Categorical Data Analysis in Lavaan
16.4
PART IV: What if you have it all?
17
Week13_1: Lavaan Lab 14 Measurement Invariance
17.1
PART I: Multi-Group Analyses, Done Incorrectly
17.2
PART II: Testing Measurement Invariance
17.2.1
step 1: Configural invariance
17.2.2
step 2: Metric (weak) invariance
17.2.3
step 3: Scalar (strong) Invariance
17.2.4
step 4: (Optional) Residual variance (strict) invariance
17.3
PART III: Shortcut to performing MI
17.3.1
measurementInvariance()
17.3.2
measEq.syntax()
17.4
PART IV: Multi-Group CFA Modeling, done right
17.4.1
Statistical Test of Equal Factor Means:
17.4.2
Statistical Test of Equal Regression Coefficients:
18
Week13_2: Lavaan Lab 15 MIMIC & Longitudinal Invariance
18.1
PART I: Partial Invariance
18.2
PART II: MIMIC
18.2.1
Test Metric Invariance
18.2.2
Test Scalar Invariance
18.2.3
Test The Hypothesis of Equal Factor Means:
18.3
PART III: Longitudinal Invariance
18.3.1
step 1: Configural invariance
18.3.2
step 1.5: Threshold invariance (for categorical indicators only)
18.3.3
RECOMMENDED PRACTICE: fit one invariance model at a time
18.3.4
step 2: Metric (weak) invariance
18.3.5
step 3: Scalar (strong) Invariance
18.3.6
step 4: Residual variance (strict) invariance
18.3.7
Shortcut Function
18.3.8
NOT RECOMMENDED: fit several invariance models at once
18.4
PART IV: Exercises: MIMIC
18.5
PART V: Exercises: Longitudinal Invariance
19
Week14: Lavaan Lab 16 Latent Growth Models
19.1
PART I: Spaghetti Plot
19.2
PART II: Growth Models
19.2.1
1. No growth model
19.2.2
2. Linear growth model
19.2.3
3. Quadratic growth model
19.2.4
4. Latent basis growth model (extension of linear growth model)
19.2.5
5. Spline Growth Model
19.2.6
Model Comparison
19.2.7
6. Final Model: Spline Growth Model with a binary treatment predictor
19.3
PART III: LGM on Latent Variables
19.3.1
Example
19.3.2
Exercise
20
Week15_1: Lavaan Lab 17 Second-order and Bifactor Models
20.1
PART I: Unidimensional model
20.2
PART II: Correlated factors model
20.3
PART III: Second-order factor Model
20.4
PART IV: Bifactor Model
20.5
PART V: Model Comparison
20.6
Exercise: Mental Ability Scale
21
Week15_2: Lavaan Lab 18 CFA of MTMM Matrix
21.1
PART I: Correlated methods specification
21.2
PART II: Correlated uniqueness specification
22
Week16: Lavaan Lab 19 Multilevel SEM
22.1
PART I: Multilevel CFA 1: within-only construct
22.2
PART II: Multilevel CFA 2: Between-only construct
22.3
PART III: Multilevel CFA 3: Shared cross-level construct
22.4
PART IV: Multilevel CFA 4: Configural construct
22.5
PART V: Multilevel CFA 5: Shared + Configural construct
22.6
PART VI: Model Comparison
22.7
PART VII: Adding Covariates to Multilevel SEM
22.7.1
Model A: Adding a within-only covariate
22.7.2
Model B: Adding a between-only covariate
22.7.3
Model C: Adding a covariate at both levels
22.8
PART VII: Final Model
Published with bookdown
EPSY:579 R Cookbook for SEM
Chapter 2
R Exercises