In our second example, we will use the built-in PoliticalDemocracy dataset.
This is a dataset that has been used by Bollen in his 1989 book on structural
equation modeling (and elsewhere). To learn more about the dataset, see its
help page and the references therein.
The figure below contains a graphical representation
of the model that we want to fit.
The corresponding lavaan syntax for specifying this model
is as follows:
In this example, we use three different formula types: latent variabele
definitions (using the =~ operator), regression formulas (using the ~
operator), and (co)variance formulas (using the ~~ operator). The regression
formulas are similar to ordinary formulas in R. The (co)variance formulas
typically have the following form:
The variables can be either observed or latent variables. If the two variable
names are the same, the expression refers to the variance (or residual
variance) of that variable. If the two variable names are different, the
expression refers to the (residual) covariance among these two variables. The
lavaan package automatically makes the distinction between variances and
In our example, the expression y1 ~~ y5 allows the residual variances of the
two observed variables to be correlated. This is sometimes done if it is
believed that the two variables have something in common that is not captured
by the latent variables. In this case, the two variables refer to identical
scores, but measured in two different years (1960 and 1965, respectively). Note
that the two expressions y2 ~~ y4 and y2 ~~ y6, can be combined into the
expression y2 ~~ y4 + y6. This is just a shorthand notation.
We enter the model syntax as follows:
To fit the model and see the results we can type:
The function sem() is very similar to the function cfa(). In fact, the two
functions are currently almost identical, but this may change in the future. In
the summary() function, we omitted the fit.measures=TRUE argument.
Therefore, you only get the basic chi-square test statistic. The argument
standardized=TRUE augments the output with standardized parameter values. Two
extra columns of standardized parameter values are printed. In the first column
(labeled Std.lv), only the latent variables are standardized. In the second
column (labeled Std.all), both latent and observed variables are
standardized. The latter is often called the 'completely standardized
The complete code to specify and fit this model is printed again below: