stephtowch / SEM-Analysis-for-Psychologists

Codes for Structural Equation Modelling for Psychologists

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Structural Equation Modelling for Psychologists

Last updated 2023-11-16.

This GitHub repository contains R code for conducting Structural Equation Modeling (SEM) with a focus on latent variables, specifically tailored for psychologists. The analysis includes a two-mediator serial mediation model that I applied in my MSc research on work addiction. As serial mediation studies are rare in Psychology literature, I'm uploading my code which may be of use to someone as a starting point which will hopefully give you the basic tools to construct, evaluate and compare Structural Equation Models (SEM; w/plots), using lavaan.

🔭 Overview

The repository is organised into the following sections:

📜 Notes

This repository assumes basic competence in R (importing, structural equation, modelling, mediation, plotting, etc) and contains only materials relating to Structural Equation Modelling in R. So the focus will be generally on the application and not on the theory.

🛠️ Setup

To run the code, you will need:

  1. A dataset relating to one independent variable, two mediator variables and one dependent variable.

  2. A fresh installation of R (preferably version 4.3.1 or above).

  3. RStudio IDE (optional but recommended).

  4. Install the required packages by running:

    # in alphabetical order:
    pkgs <- c(
      "careless", "dplyr", "knitr", "lavaan", "lavaanPlot", "mvnormalTest",
      "psych", "pwr", "semPlot", "tidyr"
    )
    
    install.packages(pkgs, repos = c("https://easystats.r-universe.dev", getOption("repos")))
    
Package Versions

Run on Windows 11 x64 (build 22621), with R version 4.3.1.

The packages used here:

  • careless 1.2.2(CRAN)
  • dplyr 1.1.3 (CRAN)
  • knitr 1.45 (CRAN)
  • lavaan 0.6-16 (CRAN)
  • lavaanPlot 0.6.2 (CRAN)
  • mvnormalTest 1.0.0 (CRAN)
  • psych 2.3.9 (CRAN)
  • pwr 1.3-0 (CRAN)
  • semPlot 1.1.6 (CRAN)
  • tidyr 1.3.0 (CRAN)

Feel free to adjust this based on your preferences and specific details about your code and setup.

About

Codes for Structural Equation Modelling for Psychologists

License:MIT License


Languages

Language:R 100.0%