Chapter 1 Introduction and R Setup

This short monograph outlines three approaches to implementing Confirmatory Factor Analysis with R, by using three separate packages. The illustration is simple, employing a 175 case data set of scores on subsections of the WISC. The idea is to fit a bifactor model where the two latent factors are the verbal and performance constructs. In this primary two-factor model, each observed variable is associated with only one latent factor. Then a second model is fit. It includes a path from both latent factors to one of the variables. Comparisons of models are then performed.

Several R packages are required for the implementations outlined in the succeeding chapters. Since CFA is implemented as a structural equation model, commercial software (e.g., LISREL, EQS, SAS) as well as open-source approaches to CFA all use SEM routines. The three primary R packages to illustrate CFA are lavaan, sem and OpenMx, along with the drawing package, semPlot. One major advantage of using R for implementation of these methods is that semPlot provides a user-friendly method for producing path diagrams of many styles by simply taking a model object from the CFA fitting functions of the other packages.

Other “housekeeping” packages are loaded here, but the three analytical packages for CFA are loaded at the point in the sequence of their usage since some common function names are shared - thus load order is important.

library(car) 
library(semPlot)
library(psych)
library(knitr)
library(kableExtra)
library(MVN)
library(dplyr)
library(magrittr)
library(tidyr)
library(corrplot)
library(ggraph)

Package citations for packages loaded here (in the above order): car (Fox, Weisberg, & Price, 2018), semPlot (Epskamp & Simon Stuber, 2017), psych (Revelle, 2019), knitr (Xie, 2018b), kableExtra (Zhu, 2019), MVN (Korkmaz, Goksuluk, & Zararsiz, 2018), dplyr (Wickham et al., 2018), magrittr (Bache & Wickham, 2014), tidyr (Wickham & Henry, 2018), corrplot (Wei & Simko, 2017)

Package citations for packages loaded elsewhere in this document: bookdown (Xie, 2018a), rmarkdown (Allaire et al., 2018), sem (Fox, Nie, & Byrnes, 2017), lavaan (Rosseel, 2018), OpenMx (Boker et al., 2019)

1.1 Caveat on this document

The present treatment of the CFA procedures is not intended to be an exhaustive analysis of this particular data set. Nor is it intended to be a thorough treatment of the CFA approaches available in R, CFA in general, or SEM in general. Rather, it is intended as a bit more than a simple introduction to CFA using R (and by implication, the nice capabilities of for Structural Equation Modeling). It provides students, who have a basic understanding of how to use R, with a reasonable introduction to CFA modeling code. The R appraoches can then be compared to their class coverage of the same analysis, done with SAS. This document provides some capabilities that may not have been covered in class, and it misses others. The learning curve for software is never at an asymptote……

1.2 Resources

The following list will provide a good start for those needing a broader in CFA modeling and more detailed sources for the primary packages empoyed in this document.

  • A comprehensive textbook treatment of SEM and CFA: (Tabachnick et al., 2019)
  • Tim Brown’s well-regarded book on CFA: (Brown, 2015)
  • Rosseel’s extensive original article on lavaan: (Rosseel, 2012)
  • El-Sheik, et al on a comparison of software for SEM: (El-Sheikh, Abonazel, & Gamil, 2017)
  • Narayanan’s review of eight SEM software approaches (Narayanan, 2012)
  • Espkamp’s helpful original article on the semPlot package: (Narayanan, 2012)

In addition, the following internet resources can be helpful.