I am interested in structural equation modeling. I am trying to get to the bottom of how $\chi^2$ is calculated for a structural equation model.
I understand that outside of structural equation modeling, $\chi^2$ is arrived at by adding up:
$$\chi^2 = \sum_{i} \frac{(O_{i}-E_{i})^2}{E_{i}}$$
for all observations. $O_{i}$ is an observed value, and $E_{i}$ is the value that we expected that observation to have.
I am definitely aware of the fact that we normally use computer software like Lavaan or Mplus to calculate $\chi^2$ for a SEM. But I'm not merely interested in the value or the digits of the answer. I'm trying to better understand where $\chi^2$ comes from, how it is arrived at, and so forth for SEM. Most explanations skip right over this very topic, and begin explaining other fit parameters such as TLI or RMSEA and accept $\chi^2$ at face value.
Can anyone go into more detail?