# Structural equation models without circular definition of latent variables

I'm trying to perform Bayesian structural equation modeling in Python and PyMC3, but I think the problem is similar for most probabilistic progamming languages, include JAGS, Stan, etc.

SEMs are often defined using equations like these:

$$$$\boldsymbol{y}=\boldsymbol{\nu}+\boldsymbol{\Lambda}\boldsymbol{\eta}+\boldsymbol{\epsilon}\\ \boldsymbol{\eta}=\boldsymbol{\alpha}+\boldsymbol{B}\boldsymbol{\eta}+\boldsymbol{\zeta}\\ \boldsymbol{\epsilon}\sim\mathrm{MvNormal}\left(0, \boldsymbol{\Theta}\right)\\ \boldsymbol{\zeta}\sim\mathrm{MvNormal}\left(0, \boldsymbol{\Psi}\right)$$$$

As you can see, the latent variables in $$\boldsymbol{\eta}$$ are defined in terms of themselves. The model makes sense because $$\boldsymbol{B}$$ is a sparse, invertible, non-symmetric matrix that defines paths between latent variables, but I'm not sure how to code this in practice. Can the second equation be re-written/expanded to so that the definition is no longer "circular" and therefore more amenable to coding?

I realize that under SEM one usually marginalizes out $$\boldsymbol{\eta}$$ and so the problem is moot. However, I think it should be possible to code it up with $$\boldsymbol{\eta}$$ explicitly sampled.

• What makes the original form difficult for coding? I fail to see May 18, 2020 at 17:14
• Defining a variable as a function of itself, which hasn't been defined yet. x = x won't work in most programming languages. May 18, 2020 at 18:30
• I wouldn't define it like that. For instance, in c++ you could do f(**f()), in Python you could pass a list of functions references. It's also more generic than naming concrete functions, this way you can pass any functions May 18, 2020 at 19:29
• Exactly, I don't want to define it that way. This is more of a question of the mathematical notation anyhow. The accepted answer perfectly understood the issue and provided the correct answer. May 18, 2020 at 19:33

Assuming $$(\mathbf{I} - \mathbf{B})$$ is invertible, we can rewrite the $$\boldsymbol{\eta}$$ equation as follows:
\begin{align} \boldsymbol{\eta} &= \boldsymbol{\alpha}+\mathbf{B}\boldsymbol{\eta}+\boldsymbol{\zeta} \\ &\Updownarrow \\ \boldsymbol{\eta} - \mathbf{B}\boldsymbol{\eta} &= \boldsymbol{\alpha}+\boldsymbol{\zeta} \\ &\Updownarrow \\ (\mathbf{I} - \mathbf{B})\boldsymbol{\eta} &= \boldsymbol{\alpha}+\boldsymbol{\zeta} \\ &\Updownarrow \\ \boldsymbol{\eta} &= (\mathbf{I} - \mathbf{B})^{-1} (\boldsymbol{\alpha}+\boldsymbol{\zeta}) \\ \end{align}
Where $$\mathbf{I}$$ is an identity matrix with the appropriate shape.