4  The matrix representation

$$

$$

While the parameter table lies at the heart of lavaan and offers a comprehensive description of the model (including all parameters, constraints, and starting values), it is not designed for numerical computation. Although essential for specifying and inspecting a model, the parameter table is not well-suited for tasks such as computing model-implied statistics or evaluating the discrepancy function. These operations are more efficiently executed using a matrix-based representation of the model. To this end, lavaan internally translates the parameter table into a set of structured model matrices. These model matrices are used for all numerical computations in the package: model fitting, optimization, and inference. In essence, the parameter table organizes and defines the model, while the matrix representation is used for the actual calculations.

Over the years, several matrix-based frameworks have been developed to represent structural equation models. One of the earliest and most influential is the LISREL approach (Jöreskog & Sörbom, 1996), which organizes models using a set of relatively small, structured matrices. A specific variant of this framework, LISREL submodel 3B, often referred to as the all-y LISREL representation, is the default system adopted by lavaan. While this is the primary internal representation, lavaan also offers limited support for the RAM (Reticular Action Model) formulation (McArdle & McDonald, 1984). However, alternative representations, such as the Bentler-Weeks representation (Bentler & Weeks, 1980), are not implemented in lavaan as of version 0.7-4.

4.1 The all-y LISREL representation

Assuming no mean structure is included and all observed variables are continuous, the all-y LISREL representation is defined by four model matrices: Lambda, Theta, Psi, and Beta:

  1. The Lambda matrix (\boldsymbol{\Lambda}) is often called the factor loadings matrix, as it contains the factor loadings of the observed variables on the latent variables (factors). It specifies how much each observed variable is related to or “loads on” each latent variable. It is typically a matrix of dimensions P\times M, where P is the number of observed variables, and M is the number of latent variables in the model.

  2. The Theta matrix (\boldsymbol{\Theta}) represents the residual variances and covariances of the observed variables in the model. The Theta matrix is a symmetric matrix with dimensions P\times P.

  3. The Psi matrix (\boldsymbol{\Psi}) contains the variances and covariances of the latent variables (factors) in the model. For exogenous latent variables these are total (co)variances; for endogenous latent variables they are residual (co)variances. The Psi matrix is a symmetric matrix of dimensions M\times M.

  4. The Beta matrix (\mathbf{B}) contains the regression coefficients that describe the relationships between latent variables. It specifies how one latent variable (or set of latent variables) predicts other latent variables. The Beta matrix is a square matrix of dimensions M\times M, but not symmetric.

If a mean structure is included, two additional components are needed:

  1. The nu vector (\boldsymbol{\nu}) contains the intercepts (or means) of the observed variables; it has dimensions P\times 1.

  2. The alpha vector (\boldsymbol{\alpha}) contains the intercepts (or means) of the latent variables; it has dimensions M\times 1.

By default, lavaan does not include a mean structure. It is automatically activated in any of the following situations:

  • meanstructure = TRUE is passed explicitly to sem(), cfa(), or a related fitting function;

  • the model syntax contains one or more intercept terms (~1) for an observed or latent variable;

  • a sample_mean vector is supplied as an argument;

  • if the lavaan() command is used, and either int_ov_free or int_lv_free is set to TRUE;

  • conditional_x = TRUE is set (the conditional approach always requires a mean structure);

  • missing = "ml" (or "fiml", "ml.x", "two.stage", or "robust.two.stage");

  • marker_int_zero = TRUE (used by default if estimator = "IV");

  • estimator = "pml" or estimator = "mml";

  • in the categorical setting (if any endogenous observed variables are categorical);

  • mimic = "Mplus" (for most estimators);

  • multiple groups are involved (i.e., the group argument is used);

  • group_equal contains "intercepts" or "means";

  • the data has a multilevel or clustered structure;

  • the growth() function is used (growth curve models have a mean structure by design).

In the all-y LISREL representation, no distinction is made between variables traditionally considered part of the ‘endogenous’ or ‘exogenous’ components of the model. Instead, all observed variables are grouped into a single random vector, denoted \mathbf{y}. A more detailed discussion of models that include observed exogenous variables \mathbf{x}, and of how to treat them differently from the \mathbf{y} variables, will be provided in Section 4.7.

For now, no distributional assumptions about the \mathbf{y} variables are made beyond treating them as continuous. Their population mean vector and variance-covariance matrix are denoted as:

\begin{aligned} \mathrm{E}(\mathbf{y}) &= \boldsymbol{\mu}\\ \text{Var}(\mathbf{y}) &= \boldsymbol{\Sigma}. \end{aligned}

With the model matrices and vectors in place, the statistical framework of structural equation modeling can now be outlined using the all-y LISREL notation. The presentation begins with the structural component, continues with the measurement model, and concludes with the derivation of the model-implied summary statistics.

4.2 The basic SEM model in all-y LISREL notation

Most structural equation models (SEMs) consist of two main components: the measurement model and the structural model. The measurement model specifies how observed variables (indicators) are related to underlying latent variables. In contrast, the structural model captures the relationships among the latent variables themselves, typically using a system of regression equations.

4.2.1 The structural model

The structural model (also called the ‘latent variable model’) is defined as:

\boldsymbol{\eta}= \boldsymbol{\alpha}+ \mathbf{B}\, \boldsymbol{\eta}+ \boldsymbol{\zeta} \tag{4.1}

where:

  • \boldsymbol{\eta} is an M\times 1 random vector of latent variables,

  • \boldsymbol{\alpha} is an M\times 1 vector of intercepts,

  • \mathbf{B} is an M\times M matrix of regression coefficients for the regressions of the latent variables on other latent variables, and

  • \boldsymbol{\zeta} is an M\times 1 random vector with two types of elements: structural errors (disturbances) for the endogenous latent variables, and deviations of the exogenous latent variables from their intercepts.

To specify the structural model in full, the following assumptions and notation are adopted:

  • The disturbances and centered exogenous latent variables have zero mean, \mathrm{E}(\boldsymbol{\zeta}) = \mathbf{0}, and their (co)variances are given by \text{Var}(\boldsymbol{\zeta}) = \boldsymbol{\Psi};

  • The diagonal elements of \mathbf{B} are zero (i.e., a variable cannot be regressed on itself);

  • The matrix (\mathbf{I} - \mathbf{B}) is invertible (where \mathbf{I} is the identity matrix of dimensions M\times M).

The model assumes that all relationships among latent variables are linear: each latent variable is expressed as a linear combination of other latent variables plus an error term. Products or powers of latent variables (latent interactions and quadratic effects) cannot be expressed in this representation. This limitation, and the alternatives that are available, are discussed in Section 4.9 later in this chapter.

If the model contains both endogenous and exogenous latent variables, it can be insightful to rewrite Equation 4.1 as:

\left( \begin{array}{c} \boldsymbol{\eta}_y\\ \boldsymbol{\eta}_x\end{array} \right) = \left( \begin{array}{c} \boldsymbol{\alpha}_{\boldsymbol{\eta}_y} \\ \boldsymbol{\alpha}_{\boldsymbol{\eta}_x} \end{array} \right) + \left( \begin{array}{cc} \mathbf{B}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_y} & \mathbf{B}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_x}\\ \mathbf{0} & \mathbf{0} \end{array} \right) \left( \begin{array}{c} \boldsymbol{\eta}_y\\ \boldsymbol{\eta}_x\end{array} \right) + \left( \begin{array}{c} \boldsymbol{\zeta}_{\boldsymbol{\eta}_y} \\ \boldsymbol{\eta}_x- \boldsymbol{\alpha}_{\boldsymbol{\eta}_x} \end{array} \right)

where:

  • \boldsymbol{\eta}_y and \boldsymbol{\eta}_x refer to endogenous and exogenous latent variables respectively;

  • The \mathbf{B}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_y} matrix contains the regression coefficients of endogenous latent variables that are regressed on (other) endogenous latent variables, while the \mathbf{B}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_x} matrix contains the regression coefficients of endogenous latent variables that are regressed on exogenous latent variables;

  • The second row is a tautology (\boldsymbol{\eta}_x= \boldsymbol{\eta}_x), which reflects that exogenous latent variables are not predicted by other latent variables in the model.

The symmetric matrix \boldsymbol{\Psi} can be partitioned as

\boldsymbol{\Psi}= \left( \begin{array}{cc} \boldsymbol{\Psi}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_y} & \boldsymbol{\Psi}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_x}\\ \boldsymbol{\Psi}_{\boldsymbol{\eta}_x,\boldsymbol{\eta}_y} & \boldsymbol{\Psi}_{\boldsymbol{\eta}_x,\boldsymbol{\eta}_x} \end{array} \right)

In most applications, \boldsymbol{\Psi}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_x} = \boldsymbol{\Psi}_{\boldsymbol{\eta}_x,\boldsymbol{\eta}_y} = \mathbf{0}, although some elements can be non-zero if the corresponding elements in \mathbf{B}_{\boldsymbol{\eta}_y,\boldsymbol{\eta}_x} are zero.

4.2.2 The reduced form of the structural model

To compute the model-implied moments of the latent variables, it is helpful to express the structural model in what is known as its reduced form. In this form, the \boldsymbol{\eta} vector of latent variables is moved to the left-hand side of the equation. Starting from the original structural equation, the \mathbf{B}\boldsymbol{\eta} term is subtracted from both sides:

\begin{aligned} \boldsymbol{\eta}- \mathbf{B}\, \boldsymbol{\eta}&= \boldsymbol{\alpha}+ \mathbf{B}\, \boldsymbol{\eta}+ \boldsymbol{\zeta}- \mathbf{B}\, \boldsymbol{\eta}\\ (\mathbf{I} - \mathbf{B})\, \boldsymbol{\eta}&= \boldsymbol{\alpha}+ \boldsymbol{\zeta} \end{aligned}

Next, pre-multiply both sides by (\mathbf{I} - \mathbf{B})^{-1}, the inverse of (\mathbf{I} - \mathbf{B}), to isolate \boldsymbol{\eta}:

\begin{aligned} \boldsymbol{\eta}&= (\mathbf{I} - \mathbf{B})^{-1}\left( \boldsymbol{\alpha}+ \boldsymbol{\zeta}\right)\\ &= (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\zeta}. \end{aligned} \tag{4.2}

This final expression in Equation 4.2 allows us to derive the model-implied moments of the latent variables. Since it is assumed that \mathrm{E}(\boldsymbol{\zeta}) = \mathbf{0}, and all other terms are constant (in the population), the model-implied mean vector of the latent variables is given by:

\mathrm{E}(\boldsymbol{\eta}) = (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}. \tag{4.3}

Similarly, because the first term in Equation 4.2 is constant, the model-implied (co)variance matrix of the latent variables becomes:

\text{Var}(\boldsymbol{\eta}) = (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Psi}\, (\mathbf{I} - \mathbf{B}^{\prime})^{-1}, \tag{4.4} where we used the fact that the transpose of an inverse is the inverse of the transpose, and therefore \left( (\mathbf{I} - \mathbf{B})^{-1} \right)^{\prime} = \left( (\mathbf{I} - \mathbf{B})^{\prime} \right)^{-1} = (\mathbf{I} - \mathbf{B}^{\prime})^{-1}.

4.2.3 The measurement model

The measurement model, also known as the ‘factor model’, describes how the observed variables are linked to underlying latent variables. It is defined as:

\mathbf{y}= \boldsymbol{\nu}+ \boldsymbol{\Lambda}\, \boldsymbol{\eta}+ \boldsymbol{\epsilon} \tag{4.5}

where:

  • \mathbf{y} is a P\times 1 random vector of observed variables,

  • \boldsymbol{\nu} is a P\times 1 vector of intercepts,

  • \boldsymbol{\Lambda} is a P\times M matrix of factor loadings,

  • \boldsymbol{\epsilon} is a P\times 1 random vector of residual errors (or measurement errors).

To specify the measurement model in full, the following assumptions and notation are adopted:

  • The residuals have zero mean, \mathrm{E}(\boldsymbol{\epsilon}) = \mathbf{0}, and their (co)variances are given by \text{Var}(\boldsymbol{\epsilon}) = \boldsymbol{\Theta};

  • The measurement errors are uncorrelated with the latent variables: \text{Cov}(\boldsymbol{\eta}, \boldsymbol{\epsilon}) = \mathbf{0};

  • The measurement errors are uncorrelated with the disturbances of the endogenous latent variables, \text{Cov}(\boldsymbol{\zeta}_{\boldsymbol{\eta}_y}, \boldsymbol{\epsilon}) = \mathbf{0}.

Since the measurement model is already in reduced form (the observed variables are directly expressed as a function of the latent variables), it is straightforward to derive the model-implied moments of the observed variables.

The model-implied mean vector of \mathbf{y} is:

\mathrm{E}(\mathbf{y}) = \boldsymbol{\nu}+ \boldsymbol{\Lambda}\, \mathrm{E}(\boldsymbol{\eta}). \tag{4.6}

The model-implied (co)variance matrix of \mathbf{y} is:

\text{Var}(\mathbf{y}) = \boldsymbol{\Lambda}\, \text{Var}(\boldsymbol{\eta}) \, \boldsymbol{\Lambda}^{\prime}+ \boldsymbol{\Theta}. \tag{4.7}

Substituting the earlier expressions for \mathrm{E}(\boldsymbol{\eta}) and \text{Var}(\boldsymbol{\eta}), the familiar expressions for the model-implied moments in SEM are obtained:

\mathrm{E}(\mathbf{y}) = \boldsymbol{\nu}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha} \tag{4.8}

and

\text{Var}(\mathbf{y}) = \boldsymbol{\Lambda}\, (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Psi}\, (\mathbf{I} - \mathbf{B}^{\prime})^{-1} \boldsymbol{\Lambda}^{\prime}+ \boldsymbol{\Theta}. \tag{4.9}

These formulas form the foundation for computing the model-implied summary statistics in SEM, which are often compared to the observed summary statistics during model fitting.

4.3 From the parameter table to the matrix representation

Once a model has been specified using lavaan model syntax and translated into a parameter table, the next step is to map the information in the parameter table onto the underlying model matrices and vectors.

Each row in the parameter table defines a specific parameter in the model, and every such parameter corresponds to a particular element in one of the model matrices. In other words, the parameter table specifies how the model matrices should be filled in. The mapping between the structure of the parameter table (specifically the lhs, op, and rhs columns) and the associated model matrix is summarized in the table below:

Mapping between the parameter table and the model matrices
Parameter type lhs op rhs Model matrix
Factor loadings latent =~ observed \boldsymbol{\Lambda}
Regression paths among latent variables latent ~ latent \mathbf{B}
Latent variable (co)variances latent ~~ latent \boldsymbol{\Psi}
Measurement error (co)variances observed ~~ observed \boldsymbol{\Theta}
Intercepts of observed variables observed ~1 \boldsymbol{\nu}
Intercepts of latent variables latent ~1 \boldsymbol{\alpha}

To make the connection between the parameter table and the model matrices more concrete, consider a simple confirmatory factor analysis model applied to the Holzinger and Swineford dataset. The model is first specified using lavaan syntax and then converted into a parameter table:

HS_model <- '
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9 
'
PT <- lavParTable(HS_model, auto_fix_first = TRUE, auto_var = TRUE, 
                  auto_cov_lv_x = TRUE)

To focus on the factor loadings, only their rows are extracted from the parameter table:

subset(PT, op == "=~")
  id     lhs op rhs user block group free ustart exo label plabel
1  1  visual =~  x1    1     1     1    0      1   0         .p1.
2  2  visual =~  x2    1     1     1    1     NA   0         .p2.
3  3  visual =~  x3    1     1     1    2     NA   0         .p3.
4  4 textual =~  x4    1     1     1    0      1   0         .p4.
5  5 textual =~  x5    1     1     1    3     NA   0         .p5.
6  6 textual =~  x6    1     1     1    4     NA   0         .p6.
7  7   speed =~  x7    1     1     1    0      1   0         .p7.
8  8   speed =~  x8    1     1     1    5     NA   0         .p8.
9  9   speed =~  x9    1     1     1    6     NA   0         .p9.

This subset of the parameter table contains nine factor loading parameters. According to the free and ustart columns, three of them (one for each latent variable) are fixed to 1 in order to set the scale (or metric) of the latent variables. The remaining six are free parameters to be estimated. Each of these nine parameters corresponds to a specific entry in the factor loading matrix \boldsymbol{\Lambda}.

In the \boldsymbol{\Lambda} matrix, each row corresponds to an observed variable, and each column corresponds to a latent variable. The precise row and column positions are determined by the order in which the observed and latent variables appear internally. This can be inspected as follows:

lavNames(PT, type = "ov")
[1] "x1" "x2" "x3" "x4" "x5" "x6" "x7" "x8" "x9"
lavNames(PT, type = "lv")
[1] "visual"  "textual" "speed"  

For example, the loading visual =~ x1 appears in the parameter table and corresponds to the first row (associated with x1) and the first column (associated with visual) of the \boldsymbol{\Lambda} matrix. Similarly, the parameter speed =~ x7 maps to the seventh row (for x7) and the third column (for speed) in the matrix.

This same mapping principle applies to all other types of parameters listed in the parameter table. For instance, the parameter x4 ~~ x4 corresponds to a diagonal element in the residual covariance matrix \boldsymbol{\Theta}, specifically the entry in the fourth row and fourth column. Likewise, the parameter textual ~~ speed refers to a covariance between two latent variables and is placed in the second row, third column of the latent variable covariance matrix \boldsymbol{\Psi}, as well as in the third row, second column, since \boldsymbol{\Psi} is a symmetric matrix.

In general, the parameter table provides the complete set of instructions for filling in the model matrices. Each parameter is mapped to a specific entry in a model matrix based on its lhs, op, and rhs fields. Parameters not present in the table correspond to fixed zeros in the model matrices. This results in a one-to-one correspondence between the parameter table and the model matrices.

4.3.1 The lavMatrixRepresentation() function

The mapping between the parameter table and the model matrices is available through the public function lavMatrixRepresentation(). It returns the parameter table with three additional columns: for each parameter, the model matrix (mat), the row index (row), and the column index (col) where that parameter is placed.

In the following example, the function is applied to the parameter table, and a selection of its columns makes explicit how each parameter is mapped to a specific position within one of the model matrices:

map <- lavMatrixRepresentation(PT)
map[, c("lhs", "op", "rhs", "free", "ustart", "mat", "row", "col")]
       lhs op     rhs free ustart    mat row col
1   visual =~      x1    0      1 lambda   1   1
2   visual =~      x2    1     NA lambda   2   1
3   visual =~      x3    2     NA lambda   3   1
4  textual =~      x4    0      1 lambda   4   2
5  textual =~      x5    3     NA lambda   5   2
6  textual =~      x6    4     NA lambda   6   2
7    speed =~      x7    0      1 lambda   7   3
8    speed =~      x8    5     NA lambda   8   3
9    speed =~      x9    6     NA lambda   9   3
10      x1 ~~      x1    7     NA  theta   1   1
11      x2 ~~      x2    8     NA  theta   2   2
12      x3 ~~      x3    9     NA  theta   3   3
13      x4 ~~      x4   10     NA  theta   4   4
14      x5 ~~      x5   11     NA  theta   5   5
15      x6 ~~      x6   12     NA  theta   6   6
16      x7 ~~      x7   13     NA  theta   7   7
17      x8 ~~      x8   14     NA  theta   8   8
18      x9 ~~      x9   15     NA  theta   9   9
19  visual ~~  visual   16     NA    psi   1   1
20 textual ~~ textual   17     NA    psi   2   2
21   speed ~~   speed   18     NA    psi   3   3
22  visual ~~ textual   19     NA    psi   1   2
23  visual ~~   speed   20     NA    psi   1   3
24 textual ~~   speed   21     NA    psi   2   3

4.3.2 Filling the model matrices

Once the mapping is known, the model matrices can be filled. lavaan does so whenever a model is set up, even when no data are provided and no fitting takes place (do_fit = FALSE), which makes it easy to see how the matrices are filled from the parameter table. To make the filling visible, every parameter is first given the value 1:

PT$ustart <- 1                        # every parameter gets the value 1
fit0 <- lavaan(PT, do_fit = FALSE)    # no data, no fitting
lavInspect(fit0, "start")
$lambda
   visual textul speed
x1      1      0     0
x2      1      0     0
x3      1      0     0
x4      0      1     0
x5      0      1     0
x6      0      1     0
x7      0      0     1
x8      0      0     1
x9      0      0     1

$theta
   x1 x2 x3 x4 x5 x6 x7 x8 x9
x1  1                        
x2  0  1                     
x3  0  0  1                  
x4  0  0  0  1               
x5  0  0  0  0  1            
x6  0  0  0  0  0  1         
x7  0  0  0  0  0  0  1      
x8  0  0  0  0  0  0  0  1   
x9  0  0  0  0  0  0  0  0  1

$psi
        visual textul speed
visual       1             
textual      1      1      
speed        1      1     1

The output is a list of matrices. In a confirmatory factor analysis (CFA) model, it typically includes lambda, theta, and psi (all lowercase). These matrices are populated based on the mapping produced by lavMatrixRepresentation(). The psi matrix is symmetric, and only its lower triangle is printed. Internally, each of its three off-diagonal elements is stored twice, so that the 24 parameters of the table fill 27 nonzero cells: the parameter table only contains the nonredundant elements of a symmetric matrix.

At this stage, the nonzero elements are only placeholders (the value 1 assigned above) until starting values are computed (chapter 6). Once the estimation process is complete, these model matrices will contain the final parameter estimates.

Since this example involves only a CFA model with no regressions among latent variables, the \mathbf{B} matrix (used for latent regressions) is entirely zero and therefore omitted from the list of model matrices.

4.3.3 Multiple groups, levels, or blocks

When a model includes multiple groups, levels, or more generally, multiple blocks, the mapping process is performed separately for each block, and the model matrices of all blocks are kept together in a single list. For example, if we estimate a CFA model with two groups, this list contains 3 \times 2 = 6 model matrices. If a mean structure is also included, the number increases to 5 \times 2 = 10 matrices and vectors.

To illustrate this, a one-factor model with two groups is fitted. lavTech() returns the matrices as one flat list, in the order in which lavaan keeps them:

model <- 'f =~ x1 + x2 + x3'
fit <- sem(model, data = HolzingerSwineford1939, group = "school")
names(lavTech(fit, "free"))
 [1] "lambda" "theta"  "psi"    "nu"     "alpha"  "lambda" "theta"  "psi"   
 [9] "nu"     "alpha" 

The list contains 10 matrices and vectors in total. The first five correspond to the first group, and the remaining five to the second group. lavInspect() returns the same matrices, but organized as a list with one element per group.

4.3.4 Observed variables in the structural model

In the LISREL representation, the structural model is defined in terms of relationships among latent variables. These relationships are captured in the Beta matrix (\mathbf{B}), which contains regression coefficients among the latent variables. However, in practice, researchers often wish to include observed variables, either as outcomes or predictors, in the structural model (e.g., regressing a latent variable on an observed covariate).

Since the \mathbf{B} matrix is strictly reserved for latent-to-latent relationships, observed variables cannot appear directly in it. The traditional solution is to “upgrade” these observed variables to latent variables. For each observed variable that appears in a structural regression (i.e., on the left or right side of a ~ operator), a corresponding latent variable is introduced and constrained to be identical to the observed variable. This is implemented by fixing the loading from the new latent variable to the observed indicator to 1 and setting the residual variance of the observed variable to 0, effectively making the two variables equivalent.

To illustrate this approach, consider a simple regression model involving only observed variables:

model <- 'y1 ~ 1 + x1 + x2 + x3'

Since all variables in this model are observed, they can be manually transformed into a corresponding ‘dummy’ latent variable to enable latent-level specification of the structural relations:

model_dummy <- '
  # create dummy latent variables
  fy1 =~ 1*y1
  fx1 =~ 1*x1
  fx2 =~ 1*x2
  fx3 =~ 1*x3
  y1 ~~ 0*y1
  x1 ~~ 0*x1
  x2 ~~ 0*x2
  x3 ~~ 0*x3
  # structural part
  fy1 ~ 1 + fx1 + fx2 + fx3
'

Although this model is algebraically equivalent to the original regression, it recasts all variables at the latent level, allowing us to work within the LISREL framework, where structural relations are defined in terms of latent variables only.

Applying this transformation manually would be cumbersome, and it is not needed: lavaan performs the transformation internally. This is demonstrated in the following example:

model <- 'y1 ~ 1 + x1 + x2 + x3'
PT <- lavParTable(model, auto_var = TRUE, fixed_x = TRUE)
map <- lavMatrixRepresentation(PT, add_attributes = TRUE)
map[, c("lhs", "op", "rhs", "free", "mat", "row", "col")]
   lhs op rhs free   mat row col
1   y1 ~1        1 alpha   1   1
2   y1  ~  x1    2  beta   1   2
3   y1  ~  x2    3  beta   1   3
4   y1  ~  x3    4  beta   1   4
5   y1 ~~  y1    5   psi   1   1
6   x1 ~~  x1    0   psi   2   2
7   x1 ~~  x2    0   psi   2   3
8   x1 ~~  x3    0   psi   2   4
9   x2 ~~  x2    0   psi   3   3
10  x2 ~~  x3    0   psi   3   4
11  x3 ~~  x3    0   psi   4   4
12  x1 ~1        0 alpha   2   1
13  x2 ~1        0 alpha   3   1
14  x3 ~1        0 alpha   4   1

As the output shows, the LISREL matrices (alpha, beta, psi) are constructed entirely in terms of latent variables, even though the original model included only observed variables. The map object includes metadata that tracks these internally generated ‘dummy’ latent variables:

attr(map, "ov.dummy.names.nox")[[1]]
[1] "y1"
attr(map, "ov.dummy.names.x")[[1]]
[1] "x1" "x2" "x3"

To inspect the actual model matrices after estimation, the model is first fitted, and the parameter estimates are extracted using lavInspect():

fit <- sem(model, data = Demo.twolevel)
lavInspect(fit, "est")
$lambda
   y1 x1 x2 x3
y1  1  0  0  0
x1  0  1  0  0
x2  0  0  1  0
x3  0  0  0  1

$theta
   y1 x1 x2 x3
y1  0         
x1  0  0      
x2  0  0  0   
x3  0  0  0  0

$psi
       y1     x1     x2     x3
y1  2.567                     
x1  0.000  0.982              
x2  0.000  0.001  1.011       
x3  0.000 -0.006  0.008  1.045

$beta
   y1  x1    x2    x3
y1  0 0.5 0.383 0.159
x1  0 0.0 0.000 0.000
x2  0 0.0 0.000 0.000
x3  0 0.0 0.000 0.000

$nu
   intrcp
y1      0
x1      0
x2      0
x3      0

$alpha
   intrcp
y1  0.026
x1 -0.007
x2 -0.003
x3  0.020

Observe that the lambda matrix includes both rows and columns labeled with the observed variables. This reflects lavaan’s convention for handling observed variables that have been internally upgraded to ‘dummy’ latent variables for structural modeling purposes. Since no true latent variables are present in this example, the lambda matrix effectively becomes an identity matrix, and all elements of the theta matrix (residual variances) are fixed to zero.

4.3.5 Higher-order factors

Higher-order factors are straightforward to specify in the model syntax using the standard =~ operator, in the same way as first-order factors. For example, if a second-order factor (g, representing a general factor) is added to the Holzinger and Swineford CFA model, the model syntax can be written as:

HS_model_ho <- '
  # first-order factors
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
  # second-order factor
  g =~ visual + textual + speed
'

Although this syntax resembles that of a typical measurement model, lavaan interprets it differently internally. Higher-order factors are not treated as being measured by the first-order factors. Instead, they are implemented as phantom latent variables that act as predictors of the first-order factors. In other words, the second-order factor model is internally reformulated as a structural model, where the first-order factors are regressed on the higher-order factor.

As a result, the higher-order “factor loadings” are stored in the beta matrix (which captures regressions among latent variables), not in the lambda matrix (which contains only first-order loadings linking latent variables to observed indicators).

To demonstrate, the second-order factor model is fitted and (a subset of) the resulting model matrices containing the final point estimates are extracted:

fit <- cfa(HS_model_ho, data = HolzingerSwineford1939)
lavInspect(fit, "est")[c("lambda", "psi", "beta")]
$lambda
   visual textul speed g
x1  1.000  0.000 0.000 0
x2  0.554  0.000 0.000 0
x3  0.729  0.000 0.000 0
x4  0.000  1.000 0.000 0
x5  0.000  1.113 0.000 0
x6  0.000  0.926 0.000 0
x7  0.000  0.000 1.000 0
x8  0.000  0.000 1.180 0
x9  0.000  0.000 1.082 0

$psi
        visual textul speed     g
visual   0.192                   
textual  0.000  0.709            
speed    0.000  0.000 0.272      
g        0.000  0.000 0.000 0.617

$beta
        visual textul speed     g
visual       0      0     0 1.000
textual      0      0     0 0.662
speed        0      0     0 0.425
g            0      0     0 0.000

Notice that the g column in the lambda matrix contains only zeros. The loadings for the second-order factor appear in the last column of the beta matrix, reflecting the regression of the first-order factors on the general factor.

4.4 Composites: a second type of construct

Up to this point, every construct in the model was a common factor: a latent variable that is reflected by its indicators, with arrows running from the construct to the observed variables through the columns of \boldsymbol{\Lambda}. lavaan supports a second type of construct: the composite, defined in the model syntax with the <~ operator (see the model syntax chapter). A composite is a weighted sum of its indicators: the arrows run from the observed variables to the construct:

c = \mathbf{w}^{\prime} \mathbf{y}_c, \tag{4.10}

where \mathbf{y}_c collects the indicators of the composite and \mathbf{w} holds the composite weights. In lavaan, factors and composites are two kinds of constructs: both are part of the latent vector \boldsymbol{\eta}, both can appear on either side of a ~ regression, and both types can be combined freely within a single model. The implementation follows the factor- and composite-based SEM framework of Schamberger et al. (2025), and is active whenever the syntax contains a <~ operator (and option composites = TRUE, the current default).

4.4.1 The weight matrix \mathbf{W}

The weights are collected in an additional model matrix, wmat (\mathbf{W}), with the same dimensions as \boldsymbol{\Lambda}: one row per observed variable, one column per construct. The columns of composites hold their weights (the first weight is fixed to 1 by default, mirroring the marker-indicator convention; with std_lv = TRUE the weights are instead rescaled such that the composite has unit variance); the columns of common factors are zero. Conversely, the \boldsymbol{\Lambda} columns of composites are zero: a construct is identified as a composite by its nonzero column in \mathbf{W}, not by an empty column in \boldsymbol{\Lambda} (a higher-order factor measured only by latent variables also has an empty \boldsymbol{\Lambda} column, and must not be mistaken for a composite).

A second element is the covariance matrix of the composite indicators. Because a composite does not restrict the covariances among its own indicators (it is formed from them, not reflected by them), their full (co)variance block is part of the model, stored in the corresponding block of \boldsymbol{\Theta}, which we denote by \boldsymbol{\Theta}_c. Note the contrast with the common-factor case, where the \boldsymbol{\Theta} entries are residual (co)variances and typically diagonal. By default, the entries of \boldsymbol{\Theta}_c are fixed to their sample counterparts; the composites_cov option controls this behavior (see the estimation chapter, Section 7.6).

4.4.2 Model-implied moments with composites

When the model contains at least one composite, the implied covariance matrix Equation 4.9 is replaced by a generalized expression. Three auxiliary matrices are needed. First, the matrix \mathbf{T} (tmat) is an identity matrix of order P, except that the block of the composite indicators is replaced by \boldsymbol{\Theta}_c. Second, the matrix \mathbf{K} is an identity matrix of order the number of constructs, except that the composite block is replaced by (\mathbf{W}^{\prime}\mathbf{T}\mathbf{W})^{-1}. For a single composite this is the scalar 1/\mathrm{Var}(c), since \mathrm{Var}(c) = \mathbf{w}^{\prime}\boldsymbol{\Theta}_c\mathbf{w}. Third, the matrix \mathbf{C}_0 equals the construct covariance matrix \text{Var}(\boldsymbol{\eta}) = (\mathbf{I} - \mathbf{B})^{-1} \boldsymbol{\Psi}(\mathbf{I} - \mathbf{B}^{\prime})^{-1}, but with the diagonal entries of the composites set to zero. The model-implied covariance matrix is then

\text{Var}(\mathbf{y}) = \mathbf{T}\,(\boldsymbol{\Lambda}+ \mathbf{W})\,\mathbf{K}\, \mathbf{C}_0\, \mathbf{K}^{\prime}\,(\boldsymbol{\Lambda}+ \mathbf{W})^{\prime}\,\mathbf{T} + \boldsymbol{\Theta}. \tag{4.11}

When no composites are present, \mathbf{W} = \mathbf{0}, \mathbf{T} and \mathbf{K} reduce to identity matrices, \mathbf{C}_0 = \text{Var}(\boldsymbol{\eta}), and Equation 4.11 collapses to the familiar Equation 4.9.

When a mean structure is present, the intercept of a composite is not a free parameter either: consistent with Equation 4.10, it is set to \alpha_c = \mathbf{w}^{\prime}\boldsymbol{\nu}_c, the weighted combination of its indicators’ intercepts. Similarly, the \boldsymbol{\Psi} entry of a composite is a derived quantity: it is set such that the total variance of the construct equals \mathbf{w}^{\prime}\boldsymbol{\Theta}_c\mathbf{w}, as dictated by Equation 4.10 (the estimation chapter describes how this works when the composite is an endogenous variable in the structural model).

4.4.3 Degrees of freedom

The default policy of fixing \boldsymbol{\Theta}_c to the sample (co)variances raises the question of how these values should be counted: they are neither free parameters nor genuine restrictions, since the model reproduces them exactly, by construction. lavaan therefore removes them from the count of sample statistics: in the computation of the degrees of freedom, the number of nonredundant moments is reduced by the number of fixed composite-indicator (co)variances (function lav_pt_ndat()). As a consistency check, refitting a composite model with composites_cov = "free", where the same entries are counted as free parameters instead of as sample statistics, yields the identical chi-square statistic and identical degrees of freedom.

4.4.4 A numerical check

As in the rest of this chapter, the algebra can be verified directly against a fitted object. We use a small model that mixes one composite with one common factor:

model <- '
  # composite construct
    ind60 <~ x1 + x2 + x3
  # common factor
    dem60 =~ y1 + y2 + y3 + y4
  # structural part: both constructs side by side
    dem60 ~ ind60
'
fit <- sem(model, data = PoliticalDemocracy)
MM <- lavInspect(fit, "est")
MM$wmat     # the weight matrix W
    ind60 dem60
y1  0.000     0
y2  0.000     0
y3  0.000     0
y4  0.000     0
x1  1.000     0
x2  0.216     0
x3 -0.109     0

The matrix \boldsymbol{\Theta} shows where the composite indicators are stored:

MM$theta
      y1    y2    y3    y4    x1    x2    x3
y1 2.343                                    
y2 0.000 6.665                              
y3 0.000 0.000 5.309                        
y4 0.000 0.000 0.000 2.198                  
x1 0.000 0.000 0.000 0.000 0.530            
x2 0.000 0.000 0.000 0.000 0.977 2.252      
x3 0.000 0.000 0.000 0.000 0.812 1.782 1.950

The rows and columns are ordered with the indicators of the common factor first, followed by the indicators of the composite. The upper left block (y1–y4) is diagonal and contains the residual variances of the common-factor indicators, as in any measurement model. The lower right block (x1–x3) is the block \boldsymbol{\Theta}_c: a full symmetric matrix that contains the (co)variances of the composite indicators, fixed to their sample values (with divisor N, the maximum-likelihood convention). The off-diagonal blocks are zero: the two sets of indicators do not share residual covariances.

4.5 Inspecting model matrices

Once a model has been estimated using lavaan, it is often useful to inspect the underlying model matrices to better understand how the parameter estimates are organized internally. This can be done using the lavInspect() function, which provides access to various internal structures of the fitted model object. The first argument of lavInspect() should always be a fitted lavaan object (often called fit).

When called without additional arguments, lavInspect() returns the model matrices with the positions of all free parameters clearly marked. The numbers shown correspond to the entries in the free column of the parameter table. To illustrate, consider a simple one-factor model. First, the parameter table is shown, followed by the model matrices:

model <- 'f =~ x1 + x2 + x3'
fit <- sem(model, data = HolzingerSwineford1939)
parTable(fit)
  id lhs op rhs user block group free ustart exo label plabel start   est    se
1  1   f =~  x1    1     1     1    0      1   0         .p1. 1.000 1.000 0.000
2  2   f =~  x2    1     1     1    1     NA   0         .p2. 0.778 0.778 0.141
3  3   f =~  x3    1     1     1    2     NA   0         .p3. 1.107 1.107 0.214
4  4  x1 ~~  x1    0     1     1    3     NA   0         .p4. 0.679 0.835 0.118
5  5  x2 ~~  x2    0     1     1    4     NA   0         .p5. 0.691 1.065 0.105
6  6  x3 ~~  x3    0     1     1    5     NA   0         .p6. 0.637 0.633 0.129
7  7   f ~~   f    0     1     1    6     NA   0         .p7. 0.050 0.524 0.130
lavInspect(fit)
$lambda
   f
x1 0
x2 1
x3 2

$theta
   x1 x2 x3
x1  3      
x2  0  4   
x3  0  0  5

$psi
  f
f 6

For this confirmatory factor analysis (CFA) model without a mean structure, only three model matrices are required: lambda, theta, and psi. The lavInspect() output uses lowercase names corresponding to these matrices. By reviewing them, the user can clearly identify the locations of the six free parameters in the model. It is considered good practice to check the model matrices to confirm that all parameters are specified correctly, ensuring that no parameters are unintentionally fixed or added. Ultimately, it is these matrices that define the computations, so they represent the definitive form of the model.

Note that, unlike the bare matrices returned by lavTech(), the model matrices returned by lavInspect() include row and column labels. These labels make it much easier to identify and interpret the positions of parameters within each matrix.

By default, lavInspect() displays the model matrices with numbered entries indicating the free parameters. This is equivalent to calling lavInspect(fit, what = "free"). Other information can be requested by specifying a different value for the what= argument. For instance, what = "start" displays the starting values of the parameters, while what = "est" returns the final parameter estimates after model fitting. A full list of available options can be found in the “Model matrices” subsection of the “Details” section in the lavInspect() documentation of the lavaan package.

4.6 The RAM representation

The Reticular Action Model (RAM) is an alternative, matrix-based representation of structural equation models, originally introduced by McArdle and McDonald (1984). It offers a unified framework for both measurement and structural relationships, using a compact set of matrices to describe all directed and undirected effects among variables.

Unlike the LISREL model (which is used by default in lavaan), the RAM formulation combines observed and latent variables into a single set of matrices. It is defined by four main components:

  1. The asymmetric matrix \mathbf{A} contains all directed effects (e.g., regressions and factor loadings), and has dimensions (P+ M) \times (P+ M).

  2. The symmetric matrix \mathbf{S} contains all undirected effects (variances and covariances), and has dimensions (P+ M) \times (P+ M).

  3. The filter matrix \mathbf{F} selects the observed variables from the full set of variables (observed and latent), and has dimensions P\times (P+ M).

  4. If a mean structure is added, the \mathbf{m} vector contains the means or intercepts of both the observed and latent variables, and has dimensions (P+ M) \times 1.

A key distinction from the LISREL approach is that RAM can easily handle relations between observed and latent variables, avoiding the need for special handling (such as “upgrading” observed variables to dummy latent variables) when including observed variables in structural equations.

Let \mathbf{v} denote the full vector of random variables (observed and latent). In the RAM formulation, no explicit distinction is made between the measurement part and the structural part of the model. Instead, the model is defined by a single equation:

\mathbf{v} = \mathbf{m} + \mathbf{A}\, \mathbf{v} + \mathbf{r}.

It is assumed that the exogenous random variables \mathbf{r} have zero mean, \mathrm{E}(\mathbf{r}) = \mathbf{0}, and their (co)variances are given by \text{Var}(\mathbf{r}) = \mathbf{S}. Furthermore, it is assumed that the diagonal elements of \mathbf{A} are zero, and that (\mathbf{I} - \mathbf{A}) is invertible.

The reduced form model can be written as:

\mathbf{v} = (\mathbf{I} - \mathbf{A})^{-1} \, \mathbf{m} + (\mathbf{I} - \mathbf{A})^{-1} \,\mathbf{r},

and it follows that the model-implied mean vector and (co)variance matrix for \mathbf{v} are given by:

\begin{aligned} \mathrm{E}(\mathbf{v}) &= (\mathbf{I} - \mathbf{A})^{-1} \, \mathbf{m}\\ \text{Var}(\mathbf{v}) &= (\mathbf{I} - \mathbf{A})^{-1} \, \mathbf{S}\, (\mathbf{I} - \mathbf{A}^{\prime})^{-1}. \end{aligned}

To obtain the moments for only the observed variables \mathbf{y}, the filter matrix \mathbf{F} is used:

\begin{aligned} \mathrm{E}(\mathbf{y}) &= \mathbf{F} \, \mathrm{E}(\mathbf{v})\\ \text{Var}(\mathbf{y}) &= \mathbf{F} \, \text{Var}(\mathbf{v}) \, \mathbf{F}^{\prime}. \end{aligned}

The connection to the all-y LISREL representation becomes clear by expressing the \mathbf{v} and \mathbf{r} vectors in all-y LISREL notation as:

\mathbf{v} = \left( \begin{array}{c} \mathbf{y}\\ \boldsymbol{\eta}\end{array} \right) \quad \text{and} \quad \mathbf{r} = \left( \begin{array}{c} \boldsymbol{\epsilon}\\ \boldsymbol{\zeta}\end{array} \right).

Similarly, the \mathbf{A} and \mathbf{S} matrices can be written as:

\mathbf{A}= \left[ \begin{array}{cc} \mathbf{0} & \boldsymbol{\Lambda}\\ \mathbf{0} & \mathbf{B}\\ \end{array} \right] \quad \quad \text{and} \quad \quad \mathbf{S}= \left[ \begin{array}{cc} \boldsymbol{\Theta}& \mathbf{0}\\ \mathbf{0} & \boldsymbol{\Psi}\\ \end{array} \right].

To use the RAM representation in lavaan, set the representation argument to "ram". The mapping function of Section 4.3.1 shows where each parameter is placed in the RAM matrices:

model <- 'f =~ y1 + y2 + y3'
PT <- lavParTable(model, auto = TRUE)
map <- lavMatrixRepresentation(PT, representation = "RAM")
map[, c("lhs", "op", "rhs", "free", "ustart", "mat", "row", "col")]
  lhs op rhs free ustart mat row col
1   f =~  y1    0      1   A   1   4
2   f =~  y2    1     NA   A   2   4
3   f =~  y3    2     NA   A   3   4
4  y1 ~~  y1    3     NA   S   1   1
5  y2 ~~  y2    4     NA   S   2   2
6  y3 ~~  y3    5     NA   S   3   3
7   f ~~   f    6     NA   S   4   4

Here, the mat column identifies whether a parameter belongs to the A or S matrix. To inspect the final estimated matrices, the model is first fitted:

fit <- sem(model, data = Demo.twolevel, representation = "ram")
lavInspect(fit, "est")
$ov.idx
       y1 y2 y3
ov.idx  1  2  3

$A
   y1 y2 y3     f
y1  0  0  0 1.000
y2  0  0  0 0.733
y3  0  0  0 0.648
f   0  0  0 0.000

$S
      y1    y2    y3     f
y1 1.010                  
y2 0.000 1.202            
y3 0.000 0.000 1.186      
f  0.000 0.000 0.000 1.978

Rather than building a full sparse F matrix, lavaan uses a simple index vector (ov.idx) to track which rows and columns in the RAM matrices correspond to observed variables.

While the RAM representation is supported for most models in lavaan, including multiple-group and multilevel models, as of version 0.7-4 it does not support:

  • Models with ordered categorical outcomes;

  • The conditional_x = TRUE option;

  • Correlation structures (correlation = TRUE) and composites (defined by the <~ operator).

4.7 Exogenous observed covariates (\mathbf{x})

Many structural equation models include observed exogenous covariates, often referred to as x-variables. When working with the parameter table, or with a fitted lavaan object, the list of x-variables can be obtained by calling the lavNames() function with the "ov_x" argument:

model <- 'y1 + y2 + y3 ~ x1 + x2 + x3'
PT <- lavParTable(model, auto = TRUE)
lavNames(PT, "ov_x")
[1] "x1" "x2" "x3"

By default, exogenous covariates are treated as external to the model. They influence other variables but are not themselves modeled. For this reason, x-variables should only appear on the right-hand side of regression formulas (i.e., using the ~ operator). If an x-variable appears elsewhere, say in an intercept (~1) or variance (~~) formula, lavaan assumes it is part of the model and removes it from the ov.x list. For example:

model <- '
  y1 + y2 + y3 ~ x1 + x2 + x3
  x1 ~ 1   # x1 intercept
  x2 ~~ x2 # x2 variance
'
PT <- lavParTable(model, auto = TRUE)
lavNames(PT, "ov_x")
[1] "x3"

In this case, only x3 remains in the ov.x list. To ensure a variable is treated as a proper exogenous covariate, it should be used only in the right-hand side of regression formulas.

From here on, the x-variables refer strictly to those variables included in the ov.x list. If this list is non-empty, lavaan supports several modeling strategies based on the values of the fixed_x and conditional_x arguments. These arguments are logical (TRUE or FALSE), giving rise to the following combinations:

Four approaches to handle exogenous observed covariates
fixed_x = FALSE fixed_x = TRUE
conditional_x = FALSE random approach fixed approach
conditional_x = TRUE (not used) conditional approach

While four combinations are technically possible, only three are meaningful. The combination fixed_x = FALSE and conditional_x = TRUE is not supported. In practice, the conditional approach (conditional_x = TRUE) assumes fixed_x = TRUE.

In the following sections, each of the three valid approaches will be examined in greater detail. For clarity, a slightly modified notation will be used: \mathbf{x} denotes the exogenous covariates (x-variables), while \mathbf{y} represents the remaining observed y-variables that are not part of \mathbf{x}. The number of x-variables is written as P_x, the number of y-variables as P_y, and the total number of observed variables is therefore P= P_y + P_x.

4.7.1 The random approach

In the random approach, both the y-variables (\mathbf{y}) and the x-variables (\mathbf{x}) are treated as random and are modeled jointly within the same system. This means that lavaan estimates not only the effects of \mathbf{x} on \mathbf{y}, but also the variances and covariances among all variables, including those within \mathbf{x}. In this setup, \mathbf{x} is not assumed to be fixed or external to the model; instead, it is assumed to arise from the same underlying population distribution as \mathbf{y}. This approach is activated by setting both fixed_x = FALSE and conditional_x = FALSE. It is most appropriate when the x-variables are not strictly controlled or manipulated, and their variation is of substantive interest. The model-implied mean vector and covariance matrix are computed over the full set of observed variables, \mathbf{z}= (\mathbf{y}, \mathbf{x}).

In the random approach, there is no need to modify the standard model formulation. The same structural and measurement model definitions from Equation 4.1 and Equation 4.5 can be used, as well as the expressions for the model-implied mean vector and covariance matrix from Equation 4.8 and Equation 4.9, with \mathbf{y} replaced by the full set of observed variables \mathbf{z}= (\mathbf{y}, \mathbf{x}).

As an example, consider a one-factor model in which the latent factor is regressed on two observed covariates. When fixed_x = FALSE and conditional_x = FALSE, lavaan treats the covariates as random and includes them in the model:

model <-'
  f =~ x1 + x2 + x3
  f ~ x4 + x5
'
lavParTable(model, auto = TRUE, fixed_x = FALSE, conditional_x = FALSE)
   id lhs op rhs user block group free ustart exo label plabel
1   1   f =~  x1    1     1     1    0      1   0         .p1.
2   2   f =~  x2    1     1     1    1     NA   0         .p2.
3   3   f =~  x3    1     1     1    2     NA   0         .p3.
4   4   f  ~  x4    1     1     1    3     NA   0         .p4.
5   5   f  ~  x5    1     1     1    4     NA   0         .p5.
6   6  x1 ~~  x1    0     1     1    5     NA   0         .p6.
7   7  x2 ~~  x2    0     1     1    6     NA   0         .p7.
8   8  x3 ~~  x3    0     1     1    7     NA   0         .p8.
9   9   f ~~   f    0     1     1    8     NA   0         .p9.
10 10  x4 ~~  x4    0     1     1    9     NA   0        .p10.
11 11  x4 ~~  x5    0     1     1   10     NA   0        .p11.
12 12  x5 ~~  x5    0     1     1   11     NA   0        .p12.

In the resulting parameter table, notice that the variances and the covariance of the x-variables (x4 and x5), shown in rows 10–12, are treated as free parameters. These values are estimated from the data, and their standard errors are computed, as shown below:

fit <- sem(model, data = HolzingerSwineford1939, fixed_x = FALSE)
parameterEstimates(fit, ci = FALSE, output = "text")
Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  f =~                                                
    x1                1.000                           
    x2                0.544    0.105    5.200    0.000
    x3                0.700    0.118    5.921    0.000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  f ~                                                 
    x4                0.321    0.076    4.214    0.000
    x5                0.015    0.067    0.224    0.823

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  x4 ~~                                               
    x5                1.098    0.107   10.258    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .x1                0.523    0.133    3.946    0.000
   .x2                1.134    0.103   11.026    0.000
   .x3                0.865    0.095    9.060    0.000
   .f                 0.685    0.144    4.758    0.000
    x4                1.351    0.110   12.268    0.000
    x5                1.660    0.135   12.268    0.000

Because this model does not include a mean structure, only the model-implied covariance matrix is returned:

lavInspect(fit, "implied")
$cov
      x1    x2    x3    x4    x5
x1 1.358                        
x2 0.455 1.382                  
x3 0.585 0.318 1.275            
x4 0.450 0.245 0.315 1.351      
x5 0.378 0.206 0.264 1.098 1.660

While the random approach is convenient, as it requires no changes to the model specification, it has several limitations:

  • When the model includes many x-variables, the number of free parameters increases significantly, since their variances, covariances, and optionally means must also be estimated.

  • This approach assumes that all variables, including the exogenous covariates, are drawn from a common multivariate (typically normal) distribution. This assumption becomes problematic when categorical (e.g., binary) x-variables are involved, as their distribution is clearly not continuous or normal.

The fixed and conditional approaches are designed to address these limitations more effectively.

4.7.2 The fixed approach

In the fixed approach, x-variables are treated as fixed and observed without error. While they are still part of the model-implied covariance structure, their means, variances, and covariances are not estimated freely; instead, they are fixed to their sample values. This reduces the number of free parameters and eliminates the need to make distributional assumptions about the x-variables.

As a result, x-variables may include binary variables, dummy-coded categorical variables, squared terms, interaction terms, or any other type of covariate, much like in standard regression modeling.

This behavior is triggered by setting fixed_x = TRUE and conditional_x = FALSE, which is also the default in lavaan when all variables are continuous. Apart from fixing the (co)variances and means of the x-variables, the model formulation remains unchanged from the random approach.

As an example, consider a one-factor model with two exogenous covariates:

model <-'
  f =~ x1 + x2 + x3
  f ~ x4 + x5 
'
fit <- sem(model, data = HolzingerSwineford1939)
parTable(fit)[,c("lhs", "op", "rhs", "user", "free", 
                 "ustart", "exo", "start", "est")]
   lhs op rhs user free ustart exo start   est
1    f =~  x1    1    0      1   0 1.000 1.000
2    f =~  x2    1    1     NA   0 0.778 0.544
3    f =~  x3    1    2     NA   0 1.107 0.700
4    f  ~  x4    1    3     NA   0 0.000 0.321
5    f  ~  x5    1    4     NA   0 0.000 0.015
6   x1 ~~  x1    0    5     NA   0 0.679 0.523
7   x2 ~~  x2    0    6     NA   0 0.691 1.134
8   x3 ~~  x3    0    7     NA   0 0.637 0.865
9    f ~~   f    0    8     NA   0 0.050 0.685
10  x4 ~~  x4    0    0     NA   1 1.351 1.351
11  x4 ~~  x5    0    0     NA   1 1.098 1.098
12  x5 ~~  x5    0    0     NA   1 1.660 1.660

In the parameter table, notice that the variances and covariances of x4 and x5 are not free parameters; they are treated as fixed constants. This is also indicated in the exo column. Their starting values (start) and estimated values (est) are identical, and coincide with their sample-based values.

As with the random approach, the model-implied statistics include both y- and x-variables:

lavInspect(fit, "implied")
$cov
      x1    x2    x3    x4    x5
x1 1.358                        
x2 0.455 1.382                  
x3 0.585 0.318 1.275            
x4 0.450 0.245 0.315 1.351      
x5 0.378 0.206 0.264 1.098 1.660

A subtle point arises when the model contains both exogenous latent variables and fixed exogenous covariates. By default, lavaan adds free covariances among the exogenous latent variables (via auto_cov_lv_x) and fixed (co)variances among the x-variables, but no covariances between the two sets. The auto_cov_x argument (introduced in the previous chapter) removes this inconsistency: if set to TRUE, the covariances between the exogenous latent variables and the x-variables are added and freed automatically, while the x-variables keep their fixed-exogenous status. In the matrix representation, these covariances are stored in the \boldsymbol{\Psi} matrix: the x-variables involved already appear as ‘dummy’ latent variables (see Section 4.3.4), and the new covariances occupy the corresponding off-diagonal elements of \boldsymbol{\Psi}. Note that auto_cov_x is ignored (with a warning) when conditional_x = TRUE, because the x-variables are then conditioned out of the model, and these covariances can no longer be represented.

4.7.3 The conditional approach

In the conditional approach, exogenous covariates (x-variables) are treated as fixed and external to the system of equations. Conceptually, this is equivalent to first regressing out the influence of the x-variables from the y-variables, and then modeling the residual (co)variation using the structural equation model.

This aligns with the logic of classical linear regression, where covariates are assumed to be non-stochastic, and the model focuses on explaining variation in the outcome variables conditional on the predictors. As a result, the model-implied statistics include:

  • a conditional intercept term,

  • a slope structure relating y-variables to x-variables, and

  • the residual (co)variance matrix of the y-variables.

To formalize this, the structural model is first written while treating the \mathbf{x} variables as random (so that the law of total expectation and variance can be applied in the derivation below):

\boldsymbol{\eta}= \boldsymbol{\alpha}+ \mathbf{B}\, \boldsymbol{\eta}+ \boldsymbol{\Gamma}\, \mathbf{x}+ \boldsymbol{\zeta} \tag{4.12}

Here, \boldsymbol{\Gamma} is a (M\times P_x) matrix of regression coefficients, and \mathbf{x} is a (P_x \times 1) vector representing the exogenous covariates.

The reduced form of the structural model becomes:

\boldsymbol{\eta}= (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \mathbf{x}+ (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\zeta}. \tag{4.13}

From this, the conditional moments of the latent variables given \mathbf{x} are:

\begin{aligned} \mathrm{E}(\boldsymbol{\eta}| \mathbf{x}) &= (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \mathbf{x}\\ \text{Var}(\boldsymbol{\eta}| \mathbf{x}) &= (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Psi}\, (\mathbf{I} - \mathbf{B}^{\prime})^{-1} \end{aligned} \tag{4.14}

The measurement model remains the same as in Equation 4.5, but the \mathbf{y} vector now includes only the y-variables. Consequently, the dimensions of \boldsymbol{\nu}, \boldsymbol{\Lambda}, and \boldsymbol{\Theta} become (P_y \times 1), (P_y \times M), and (P_y \times P_y), respectively.

Substituting the reduced-form expression for \boldsymbol{\eta} into the measurement model yields:

\mathbf{y}= \boldsymbol{\nu}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \mathbf{x}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\zeta}+ \boldsymbol{\epsilon}

This can be rewritten as a multivariate regression model:

\mathbf{y}= \boldsymbol{\gamma}+ \boldsymbol{\Pi}\, \mathbf{x}+ \boldsymbol{\delta}

where:

\begin{aligned} \boldsymbol{\gamma}&= \boldsymbol{\nu}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}\\ \boldsymbol{\Pi}&= \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\\ \boldsymbol{\delta}&= \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\zeta}+ \boldsymbol{\epsilon}. \end{aligned}

The conditional moments of the observed y-variables are thus:

\begin{aligned} \mathrm{E}(\mathbf{y}| \mathbf{x}) &= \boldsymbol{\gamma}+ \boldsymbol{\Pi}\mathbf{x}\\ &= \boldsymbol{\nu}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \mathbf{x}\\ &= \boldsymbol{\nu}+ \boldsymbol{\Lambda}\, \mathrm{E}(\boldsymbol{\eta}| \mathbf{x})\\ \text{Var}(\mathbf{y}| \mathbf{x}) &= \text{Var}( \boldsymbol{\delta})\\ &= \boldsymbol{\Lambda}\, (\mathbf{I} - \mathbf{B})^{-1} \boldsymbol{\Psi}\, (\mathbf{I} - \mathbf{B}^{\prime})^{-1}\boldsymbol{\Lambda}^{\prime}+ \boldsymbol{\Theta} \end{aligned}

Note that the conditional expectation depends on \mathbf{x} and varies with its values, while the residual covariance matrix, \text{Var}(\mathbf{y}| \mathbf{x}), is constant and does not depend on \mathbf{x}.

In summary, the model-implied summary statistics used in the estimation process in the conditional approach are:

  1. The (residual) intercept: \boldsymbol{\gamma}= \boldsymbol{\nu}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}

  2. The slope structure: \boldsymbol{\Pi}= \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}

  3. The residual (co)variance matrix: \text{Var}(\boldsymbol{\delta}) = \text{Var}(\mathbf{y}| \mathbf{x}).

To illustrate, the one-factor model with two exogenous covariates is fitted again, but this time using conditional_x = TRUE:

model <-'
  f =~ x1 + x2 + x3
  f ~ x4 + x5 
'
fit <- sem(model, data = HolzingerSwineford1939,
           conditional_x = TRUE)
parTable(fit)[,c("lhs", "op", "rhs", "user", "free", 
                 "exo", "start", "est")]
   lhs op rhs user free exo start   est
1    f =~  x1    1    0   0 1.000 1.000
2    f =~  x2    1    1   0 0.837 0.544
3    f =~  x3    1    2   0 1.288 0.700
4    f  ~  x4    1    3   1 0.000 0.321
5    f  ~  x5    1    4   1 0.000 0.015
6   x1 ~~  x1    0    5   0 0.584 0.523
7   x2 ~~  x2    0    6   0 0.674 1.134
8   x3 ~~  x3    0    7   0 0.619 0.865
9    f ~~   f    0    8   0 0.050 0.685
10  x4 ~~  x4    0    0   1 1.351 1.351
11  x4 ~~  x5    0    0   1 1.098 1.098
12  x5 ~~  x5    0    0   1 1.660 1.660
13  x1 ~1        0    9   0 3.719 3.887
14  x2 ~1        0   10   0 5.515 5.517
15  x3 ~1        0   11   0 1.916 1.516
16  x4 ~1        0    0   1 3.061 3.061
17  x5 ~1        0    0   1 4.341 4.341
18   f ~1        0    0   0 0.000 0.000

Several aspects stand out in the parameter table:

  • A mean structure is included automatically. This is always the case when conditional_x = TRUE.

  • The exo column contains values for the regression coefficients (in rows 4–5), which is how lavaan distinguishes the conditional approach from the fixed approach.

However, the most notable differences appear in the model-implied statistics:

lavInspect(fit, "implied")
$res.cov
      x1    x2    x3
x1 1.208            
x2 0.373 1.337      
x3 0.480 0.261 1.201

$res.int
   x1    x2    x3 
3.887 5.517 1.516 

$res.slopes
      x4    x5
x1 0.321 0.015
x2 0.175 0.008
x3 0.225 0.011

$cov.x
      x4    x5
x4 1.351      
x5 1.098 1.660

$mean.x
   x4    x5 
3.061 4.341 

The output contains a list with five components:

  • res.cov: the residual (co)variance matrix of the y-variables (after regressing out the x-variables)

  • res.int: the residual intercept vector for the y-variables

  • res.slopes: the model-implied slope structure for the regression of \mathbf{y} on \mathbf{x}

  • cov.x: the sample-based (co)variance matrix of the x-variables

  • mean.x: the sample-based mean vector of the x-variables

Technically, the last two components (cov.x and mean.x) are not part of the model-implied statistics. They are the empirical moments of the x-variables. However, they are included for convenience, as they are necessary for computing the unconditional model-implied statistics, as explained in the next section.

4.7.4 The connection between the fixed and the conditional approach

It may appear that the conditional approach differs substantially from the fixed approach, especially when comparing their model-implied statistics. Yet, both approaches yield identical point estimates. This equivalence holds because the conditional model can always be embedded in an equivalent unconditional one, as the derivation below shows.

To establish this connection, the unconditional moments are derived from the conditional formulation. The unconditional expectation and variance of the latent variables are given by:

\begin{aligned} \mathrm{E}(\boldsymbol{\eta}) &= \mathrm{E}\left[ \mathrm{E}(\boldsymbol{\eta}| \mathbf{x}) \right]\\ &= (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \mathrm{E}(\mathbf{x})\\ \text{Var}(\boldsymbol{\eta}) &= \mathrm{E}\left[ \text{Var}(\boldsymbol{\eta}| \mathbf{x}) \right] + \text{Var}\left[ \mathrm{E}(\boldsymbol{\eta}| \mathbf{x}) \right]\\ &= (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Psi}(\mathbf{I} - \mathbf{B}^{\prime})^{-1}+ (\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \text{Var}( \mathbf{x}) \, \boldsymbol{\Gamma}^{\prime} (\mathbf{I} - \mathbf{B}^{\prime})^{-1}\\ &= (\mathbf{I} - \mathbf{B})^{-1} \left[ \boldsymbol{\Psi}+ \boldsymbol{\Gamma}\, \text{Var}( \mathbf{x}) \, \boldsymbol{\Gamma}^{\prime} \right] (\mathbf{I} - \mathbf{B}^{\prime})^{-1}. \end{aligned}

From these, the unconditional implied moments of the observed variables can be derived:

\begin{aligned} \mathrm{E}(\mathbf{y}) &= \boldsymbol{\nu}+ \boldsymbol{\Lambda}\, \mathrm{E}(\boldsymbol{\eta}) \\ &= \boldsymbol{\nu}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\alpha}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \mathrm{E}(\mathbf{x})\\ &= \boldsymbol{\gamma}+ \boldsymbol{\Pi}\, \mathrm{E}(\mathbf{x})\\ \text{Var}(\mathbf{y}) &= \boldsymbol{\Lambda}\left[ \text{Var}(\boldsymbol{\eta}) \right] \boldsymbol{\Lambda}^{\prime}+ \boldsymbol{\Theta}\\ &= \boldsymbol{\Lambda}\, \left[ (\mathbf{I} - \mathbf{B})^{-1}\left[ \boldsymbol{\Psi}+ \boldsymbol{\Gamma}\, \text{Var}(\mathbf{x}) \, \boldsymbol{\Gamma}^{\prime} \right] \, (\mathbf{I} - \mathbf{B}^{\prime})^{-1}\right] \boldsymbol{\Lambda}^{\prime}+ \boldsymbol{\Theta}\\ &= \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Psi} (\mathbf{I} - \mathbf{B}^{\prime})^{-1}\boldsymbol{\Lambda}^{\prime}+ \boldsymbol{\Theta}+ \boldsymbol{\Lambda}(\mathbf{I} - \mathbf{B})^{-1}\boldsymbol{\Gamma}\, \text{Var}( \mathbf{x}) \, \boldsymbol{\Gamma}^{\prime} (\mathbf{I} - \mathbf{B}^{\prime})^{-1}\boldsymbol{\Lambda}^{\prime}\\ &= \text{Var}(\mathbf{y}| \mathbf{x}) + \boldsymbol{\Pi}\, \text{Var}( \mathbf{x}) \, \boldsymbol{\Pi}^{\prime}. \end{aligned}

These results show that every conditional model can be embedded within an unconditional model. In fact, the unconditional model-implied moments of the joint vector \mathbf{z}= (\mathbf{y}, \mathbf{x}), derived from the conditional formulation, are:

\begin{aligned} \mathrm{E}( \mathbf{z}) &= \left( \begin{array}{c} \boldsymbol{\gamma}+ \boldsymbol{\Pi}\, \mathrm{E}(\mathbf{x})\\ \mathrm{E}(\mathbf{x}) \end{array} \right)\\ \text{Var}(\mathbf{z}) &= \left( \begin{array}{cc} \text{Var}(\mathbf{y}| \mathbf{x}) + \boldsymbol{\Pi}\, \text{Var}( \mathbf{x}) \, \boldsymbol{\Pi}^{\prime} & \boldsymbol{\Pi}\, \text{Var}( \mathbf{x}) \\ \text{Var}( \mathbf{x}) \, \boldsymbol{\Pi}^{\prime} & \text{Var}( \mathbf{x}) \end{array} \right). \end{aligned}

In the formal description above, the \mathbf{x} variables were treated as random for notational convenience. In practical applications, however, \mathbf{x} is typically treated as fixed. This permits the substitution of \mathrm{E}(\mathbf{x}) and \text{Var}(\mathbf{x}) with their sample-based mean vector and (co)variance matrix, respectively.

To demonstrate the link between the conditional and joint (fixed or random) formulations, the unconditional (co)variance matrix of the complete set of observed variables (both y- and x-variables) can be reconstructed using only the model-implied statistics from the conditional model:

model <-'
  f =~ x1 + x2 + x3
  f ~ x4 + x5 
'
fit <- sem(model, data = HolzingerSwineford1939,
           conditional_x = TRUE)
implied <- lavInspect(fit, "implied")
res_cov <- implied$res.cov 
res_slopes <- implied$res.slopes 
cov_x <- implied$cov.x
z_yy <- res_cov + res_slopes %*% cov_x %*% t(res_slopes)
z_yx <- res_slopes %*% cov_x 
z_xy <- cov_x %*% t(res_slopes)
z_xx <- cov_x
rbind( cbind(z_yy, z_yx),
       cbind(z_xy, z_xx) )
          x1        x2        x3        x4        x5
x1 1.3583698 0.4547034 0.5851216 0.4503244 0.3775683
x2 0.4547034 1.3817838 0.3184955 0.2451222 0.2055194
x3 0.5851216 0.3184955 1.2748648 0.3154282 0.2644665
x4 0.4503244 0.2451222 0.3154282 1.3506645 1.0977528
x5 0.3775683 0.2055194 0.2644665 1.0977528 1.6597858

This reconstructed matrix represents the model-implied joint (co)variance matrix of the full observed vector (\mathbf{y}, \mathbf{x}), as implied by the conditional model.

The reader may wish to compare this result to the joint (co)variance matrix returned by the fixed and random approaches. The comparison demonstrates that, despite differing parameterizations, all three formulations are statistically equivalent in terms of their model-implied moments.

4.8 The categorical setting

Ordered categorical (ordinal) endogenous variables are the subject of chapter 14, which covers the latent response formulation, the estimation of thresholds and polychoric correlations, the WLS family of estimators, pairwise maximum likelihood, and the treatment of multiple groups and occasions. This section only introduces the model matrices and vectors that are added to the LISREL set when ordinal variables are present. The statistical background is summarized only as far as it is needed to understand what these matrices contain.

The starting point is that each ordinal variable y_p is represented by a continuous latent response variable y^{\star}_p, and that the structural and measurement models of Equation 4.1 and Equation 4.5 are specified for the vector of latent responses \mathbf{y}^{\star} instead of \mathbf{y} (Section 14.2). The standard model matrices (\boldsymbol{\Lambda}, \boldsymbol{\Theta}, \boldsymbol{\Psi}, \mathbf{B}) are therefore unchanged in form and meaning; they now describe relations among the latent responses.

Two additional matrices are needed in the categorical setting:

  • The tau matrix (\boldsymbol{\tau}) contains the thresholds that cut the latent response into categories. A variable with C_p categories has C_p- 1 thresholds. The thresholds of all ordinal variables are stacked in a single column matrix, with rows labeled y_p|t1, y_p|t2, and so on. They take over the role of the intercepts, whose entries in \boldsymbol{\nu} are (usually) fixed to zero for ordinal variables.

  • The delta matrix (\boldsymbol{\Delta}) is a diagonal matrix of scaling factors, one per observed variable (equal to one for continuous variables). It implements the unit-variance constraint on the latent responses. Under the (current) default Delta parameterization, the diagonal of \boldsymbol{\Delta} is fixed to one and the residual variances of the ordinal variables (the corresponding diagonal elements of \boldsymbol{\Theta}) are derived from the constraint rather than estimated. Under the Theta parameterization, the residual variances are fixed to one and the elements of \boldsymbol{\Delta} are derived instead. The formulas, and the situations in which the choice matters, are given in Section 14.5.2.

The model-implied moments are the thresholds and the covariance matrix of the latent responses, which is a correlation matrix for the ordinal variables; the expression that combines the standard matrices with \boldsymbol{\Delta} is given in Section 14.5.1. Finally, when exogenous covariates are present, conditional_x = TRUE is the (current) default in the categorical setting, so that the gamma matrix (\boldsymbol{\Gamma}) of Section 4.7.3 appears as well. This matrix is not specific to ordinal data: it contains the regression coefficients of the latent variables on the exogenous covariates, exactly as in the conditional approach for continuous variables.

To see the matrices, a one-factor model with three ordered indicators and two exogenous covariates is fitted. Since lavaan contains no built-in dataset with ordinal variables, three continuous variables from Demo.twolevel are discretized into four ordered categories:

d <- Demo.twolevel
d$y1o <- cut(d$y1, breaks = 4, labels = 1:4)
d$y2o <- cut(d$y2, breaks = 4, labels = 1:4)
d$y3o <- cut(d$y3, breaks = 4, labels = 1:4)

The one-factor model is then specified and fitted:

model <- '
  f =~ y1o + y2o + y3o
  f ~ x1 + x2
'
fit <- cfa(model, data = d, ordered = c("y1o", "y2o", "y3o"))
lavInspect(fit, "est")
$lambda
        f
y1o 1.000
y2o 0.884
y3o 0.834

$theta
      y1o   y2o   y3o
y1o 0.477            
y2o 0.000 0.591      
y3o 0.000 0.000 0.636

$psi
      f
f 0.523

$nu
    intrcp
y1o      0
y2o      0
y3o      0

$alpha
  intrcp
f      0

$tau
       thrshl
y1o|t1 -2.867
y1o|t2 -0.606
y1o|t3  1.561
y2o|t1 -1.656
y2o|t2  0.347
y2o|t3  2.392
y3o|t1 -2.192
y3o|t2 -0.018
y3o|t3  2.178

$delta
    scales
y1o      1
y2o      1
y3o      1

$gamma
     x1    x2
f 0.328 0.248

$cov.x
      x1    x2
x1 0.983      
x2 0.001 1.012

$mean.x
   intrcp
x1 -0.007
x2 -0.003

Next to the standard matrices, the output shows the three additional ones. The tau matrix contains three thresholds per indicator, as expected for four categories. The delta matrix is diagonal, so only its diagonal elements are shown; all are equal to one, in line with the default Delta parameterization, under which the diagonal of theta is derived rather than estimated. The gamma matrix is a 1 \times 2 matrix with the regression coefficients of the factor f on the covariates x1 and x2.

4.9 Latent interactions and other nonlinear effects

All results in this chapter rest on one assumption that has received little attention so far: the structural model is linear in the latent variables. In Equation 4.1, each latent variable is a linear combination of the other latent variables plus a disturbance, and the model-implied moments follow from that linearity. This section discusses models that go beyond it, typically by including a latent interaction (the effect of \eta_1 on \eta_3 depends on the level of \eta_2) or a latent quadratic effect, and why this extension falls outside the framework of this chapter. We keep the discussion at the conceptual level; the details of how lavaan handles these models are given in Section 18.10, and pointers to other software are collected at the end.

4.9.1 What the problem is

Consider the simplest case: two exogenous latent variables \eta_1 and \eta_2, an endogenous latent variable \eta_3, and a structural equation with an interaction term,

\eta_3 = \alpha_3 + \gamma_1 \eta_1 + \gamma_2 \eta_2 + \gamma_3 \eta_1 \eta_2 + \zeta_3. \tag{4.15}

Products of observed variables pose no problem. If x1 and x2 are observed, the model syntax y ~ x1 + x2 + x1:x2 makes lavaan compute the product x1:x2 as one more column of the data set, and from then on the computations of this chapter treat that column like any other (rather nonnormal) observed variable. Its treatment in the standardized solution is discussed in Section 12.1.6.

A product of latent variables is different, for two reasons. The first is representational: no element of \mathbf{B}\,\boldsymbol{\eta} can represent the term \gamma_3 \eta_1 \eta_2. One could try to append the product as an extra “latent variable” \eta_4 = \eta_1 \eta_2 to \boldsymbol{\eta}, with a row and column in \mathbf{B} and \boldsymbol{\Psi}. But then the second problem appears: the moments of \eta_4 are not free parameters. If \eta_1 and \eta_2 are jointly normal with zero means and covariance matrix \boldsymbol{\Psi}_{12} (elements \psi_{11}, \psi_{22}, \psi_{12}), then

\mathrm{E}(\eta_1 \eta_2) = \psi_{12}, \qquad \text{Var}(\eta_1 \eta_2) = \psi_{11}\psi_{22} + \psi_{12}^2, \qquad \text{Cov}(\eta_1, \eta_1 \eta_2) = \text{Cov}(\eta_2, \eta_1 \eta_2) = 0,

so the “variance” of the product term and its covariances with its components are nonlinear functions of the parameters that are already in the model. Moreover, \eta_4 has no indicators of its own, and it is not normally distributed even when \eta_1 and \eta_2 are. Because \eta_1 \eta_2 is uncorrelated with \eta_1 and \eta_2, the interaction coefficient \gamma_3 does not appear in any covariance between the indicators of \eta_3 and those of \eta_1 or \eta_2; it only enters the variance of \eta_3, where it is confounded with the disturbance variance. In other words, the sample mean vector and covariance matrix of the original indicators, the only data used in this chapter, do not identify \gamma_3. To estimate a latent interaction, one needs additional information: extra sample moments (products of indicators), a distributional assumption that ties the nonnormality of the outcome to \gamma_3, or an estimate of the latent variables themselves. Each of these options corresponds to a family of methods in the literature.

Because the linear model matrices cannot express such a model, the lavaan()/sem()/cfa() functions do not accept product terms that involve a latent variable. The model is rejected with an error message that points to the alternatives:

model_int <- '
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
  speed ~ visual + textual + visual:textual
'
fit <- sem(model_int, data = HolzingerSwineford1939)
Error:
! lavaan->lav_step01_ovnames_checklv():  
   Interaction terms involving latent variables (visual:textual) are not 
   supported. Either use the sam() function, or consider using the modsem 
   package.

4.9.2 Approaches in the literature

The literature on latent interactions is large; what follows is an overview, not a review. Four families of methods can be distinguished, and the grouping follows the three kinds of “additional information” identified above.

Product-indicator approaches. The oldest strategy, introduced by Kenny and Judd (1984), stays entirely within the linear framework by creating observed products of indicators: if x_1, x_2 measure \eta_1 and z_1, z_2 measure \eta_2, then products such as x_1 z_1 and x_2 z_2 serve as indicators of the product factor \eta_1 \eta_2. The loadings and residual variances of these product indicators are (under normality) nonlinear functions of the loadings and variances of the original indicators, and the constrained approach (Jöreskog & Yang, 1996; Kenny & Judd, 1984) imposes these functions as nonlinear equality constraints, together with the moment relations displayed above and, in general, a mean structure. The constraints are tedious to write, sensitive to nonnormality, and their number grows quickly with the number of product indicators; much of the later literature aims to avoid them. The unconstrained approach of Marsh et al. (2004) omits them and estimates the product-indicator parameters freely, using mean-centered indicators and matched pairs of products. Residual centering or orthogonalizing (Little et al., 2006) regresses each product indicator on the original indicators and uses the residuals, and double mean centering (Lin et al., 2010) centers the indicators before and the products after multiplication; both aim to make the product factor uncorrelated with its components without constraints. All of these variants can be written in ordinary lavaan syntax once the product indicators exist in the data frame (the semTools package provides helpers for creating them), so they require no special software. But they inherit the nonnormality of the product indicators (robust standard errors are essential), depend on the choice and matching of product pairs, and become unwieldy when several interaction or quadratic terms are needed.

Distribution-analytic approaches. Instead of adding indicators, these methods work with the original indicators and use the second option above: they model the nonnormal distribution that the interaction induces in the indicators of \eta_3. The latent moderated structural equations (LMS) method of Klein and Moosbrugger (2000) assumes normal exogenous latent variables and writes the joint distribution of the indicators as a mixture of normal distributions, conditional on the latent variables in the product; the likelihood is then maximized by an EM algorithm with numerical integration over those latent variables. The quasi-maximum likelihood (QML) method of Klein and Muthén (2007) replaces the exact distribution by an approximation that is much faster to evaluate, at a small cost in efficiency, and scales better when several nonlinear terms are present. LMS is generally regarded as the reference maximum-likelihood method for the single-interaction case, but its assumptions (normal exogenous factors) matter, and the cost of the numerical integration grows with the number of latent variables that enter product terms. LMS is available natively in Mplus and, for models written in lavaan syntax, through the modsem package, which implements both LMS and QML.

Moment- and factor-score-based approaches. The third option estimates the latent variables, or their moments, first. Bollen (1995) proposed a two-stage least squares estimator that uses indicators as instrumental variables and needs no distributional assumption. Wall and Amemiya (2000) developed a two-stage method-of-moments procedure for polynomial structural equations: factor scores are computed from the measurement model, and the biased moments of their products are corrected analytically before the structural coefficients are estimated. The structural-after-measurement (SAM) approach of chapter 18 belongs to this family (Rosseel et al., 2025). Its stepwise logic is well suited to the problem: the structural part of a local SAM analysis does not use the raw data, only the mean vector and covariance matrix of the latent variables, and if those moments can be estimated for the extended latent vector (\eta_1, \eta_2, \eta_3, \eta_1 \eta_2), from products of factor scores with a bias correction based on the measurement estimates, then the structural regression proceeds as in the linear case, with the product term as one additional column. This is why the sam() function accepts f1:f2, f1:f1, and mixed f1:x1 terms directly, why it remains fast when dozens of such terms are included, and why the corresponding model matrices never need a nonlinear entry. The simulation evidence in Rosseel et al. (2025) and Vieira et al. (2026) supports this approach as a practical and accurate alternative to the one-step methods, especially when the number of nonlinear terms grows.

Bayesian approaches. Finally, in a Bayesian analysis the latent variables are sampled along with the parameters, and a nonlinear structural equation is no harder to handle than a linear one (Arminger & Muthén, 1998). The usual costs apply: prior specification, computing time, and convergence monitoring.

4.9.3 Where to look in this book

Latent interactions are discussed in two other places:

  • in chapter 18, Section 18.10 explains how sam() estimates the moments of the extended latent vector, the bias and lambda corrections involved, the local standard errors, and the interplay with missing data, and works through an example;

  • in chapter 12, Section 12.1.6 discusses how product terms, both observed and latent, are treated in the standardized solution.

In our view, the SAM approach is the preferred one within lavaan for most applied settings, and LMS (via modsem) remains the reference method for the standard case of a single interaction between normal exogenous factors.

4.10 Overview of model matrices

The table below summarizes all model matrices used internally by lavaan in the all-y LISREL representation, along with their dimensions and the conditions under which they appear. In the table, P denotes the number of observed variables, M the number of latent variables, and P_x the number of exogenous covariates. When conditional_x = TRUE, the dimensions involving P apply only to the endogenous y-variables (P_y).

Table 4.1: Overview of model matrices in the all-y LISREL representation
Matrix Symbol Description Dimensions Condition
lambda \boldsymbol{\Lambda} Factor loadings of observed on latent variables P\times M Always
theta \boldsymbol{\Theta} Residual (co)variances of observed variables P\times P Always
psi \boldsymbol{\Psi} (Co)variances of latent variables M\times M Always
beta \mathbf{B} Regression coefficients among latent variables M\times M When structural regressions are present
nu \boldsymbol{\nu} Intercepts of observed variables P\times 1 When a mean structure is present
alpha \boldsymbol{\alpha} Intercepts of latent variables M\times 1 When a mean structure is present
tau \boldsymbol{\tau} Thresholds for ordered categorical variables n_\tau \times 1 When ordered categorical variables are present
delta \boldsymbol{\Delta} Scaling parameters for the unit-variance constraint P\times P When ordered categorical variables are present
gamma \boldsymbol{\Gamma} Regression coefficients of latent variables on exogenous covariates M\times P_x When conditional_x = TRUE
wmat \mathbf{W} Composite weights of observed variables on composites P\times M When composites (<~) are present

Here, n_\tau = \sum_p (C_p- 1) is the total number of thresholds across all ordered categorical variables, where C_p denotes the number of categories of variable p.

When the RAM representation is used (representation = "ram"), the matrices lambda, theta, psi, and beta are replaced by two matrices that jointly capture all directed and undirected effects:

Table 4.2: Model matrices in the RAM representation
Matrix Symbol Description Dimensions Condition
A \mathbf{A} All directed effects (regressions and factor loadings) (P+ M) \times (P+ M) Always
S \mathbf{S} All undirected effects (variances and covariances) (P+ M) \times (P+ M) Always
m \mathbf{m} Intercepts of observed and latent variables (P+ M) \times 1 When a mean structure is present

As of version 0.7-4, the RAM representation only supports continuous variables.

4.11 Preparing for model estimation

With the matrix representation, the model specification is almost complete. At this point, all parameters have been mapped to specific elements of the model matrices, and the algebraic framework is in place to derive model-implied variances, covariances, means, and other relevant quantities. However, this description is still purely theoretical: it tells us what the model would imply, but it does not yet take the actual dataset into account.

To move from model specification to model estimation, the next step is to introduce the data. This requires computing sample statistics from the observed data, such as means, variances, covariances, and (if necessary) thresholds or polychoric correlations. These sample statistics serve as the empirical counterpart to the model-implied quantities. They also provide the information needed to derive starting values for the free parameters. Starting values are crucial because most estimation methods in structural equation modeling are iterative: the optimizer begins at the starting values and then updates them step by step until the estimates converge to values that minimize (or maximize) a chosen fitting criterion.

In other words, the parameter table and the matrix representation define the model, but the data supply the empirical targets against which the model is evaluated. Only once the model structure and the sample statistics are both in place can estimation begin.

4.12 Implementation notes

This section collects details that are tied to the current implementation of lavaan (the R package, version 0.7-4) rather than to the concepts of the main text. Internal file and function names may change or move at any release, while everything reachable through the user interface stays put. Table 4.3 maps the functions of this chapter to their source files.

The model matrices are stored in the @Model slot of the fitted object (an object of class lavmodel, built by lav_model() from the parameter table through lav_lisrel() or lav_ram()), as one flat list named GLIST. The name has a history: the list was first called MLIST (matrix list), was renamed GLIST (G for group) when multiple groups were introduced, and kept that name when blocks generalized groups, although BLIST would now be more accurate. lavTech(fit, "free") and its relatives return this list as is; lavInspect() reorganizes it per group and adds row and column labels.

Table 4.3: Source files behind the matrix representation.
Topic File(s)
LISREL-style mapping (lav_lisrel()) and model-implied moments (lav_lisrel_sigma(), including the composite case, and lav_lisrel_comp_set_intresvar()) lav_representation_lisrel.R
RAM mapping (lav_ram()) lav_representation_ram.R
building the internal model object (lav_model()) lav_model.R
public mapping function lavMatrixRepresentation() lav_representation.R
counting the sample statistics for the degrees of freedom (lav_pt_ndat()) lav_partable_utils.R