1. Create Diagrams with semPaths()
In this last section, we will use a separate library, semPlot to diagram the models we have been building.
2. semPlot and semPaths()
semPlot is a library that allows you to diagram your fitted SEM model. These diagrams are useful to make sure you have the intended specified the model and to obtain a graphical view of the final model.
First, you will load both the lavaan and semPlot packages and specify a model. Here we are using our two factor text-speed model as an example. Next, use the cfa() function to save the analyzed model. We will use the semPaths() function to create model diagrams. The first argument to the semPaths() function is our saved fitted model object.
3. semPaths() Default Output
Here is the default output from semPaths(). The double headed arrows on variables indicate that they are variances, while the double headed arrows between latents are covariances. The dashed straight arrows indicate marker variables for the coefficient estimates.
4. Editing the Picture
semPaths() has an amazing number of options to edit your graph, and we can only cover a few of them here. Two things we can start with are to add the estimates to the diagram and increase the default font size of the estimate labels.
The whatLabels argument indicates what text to depict on the single and double headed lines. You can set whatLabels to "par" to show the unstandardized estimates or set it to "std" to show the standardized estimates. The edge label cex argument indicates the font size for the edge labels, which are the numbers on the parameter arrows. Since we generally interpret the standardized solution, we can use "std" to show those numbers and a cex size of 1 to increase the font size.
5. Picture Layout
Another set of practical options are the layout and rotation options. Layout options include: "tree", which is the default; "circle"; "spring"; "tree2"; and "circle2". The best option will depend on the number of manifest and latent variables in your model.
6. Picture Rotation
The rotation argument allows you to rotate models, which is useful if you have a lot of manifest variables. This option is only paired with the tree layouts. The default is 1 with latent variables on top and manifest variables on bottom. To rotate the model counterclockwise, use 2, 3, and 4.
7. Color Visualization
One last option is the what argument. The what argument colors the parameter arrows in your model based on the strength of your estimates using either "par" or "std", similar to the whatLabels argument. edge dot color changes the color of the shading.
8. Let's practice!
Let's create model diagrams!