Chi Squared Fit Statistic in Structural Equation Models 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?
 A: It's actually kind of similar. The data you observe is the fitted covariance matrix ($\Sigma$), the data you expect is the sample covariance matrix ($S$).
You fit the model by maximum likelihood - that is, you estimate the parameters of the model such that the difference between the sample covariance matrix ($S$) and the fitted covariance ($\Sigma$) matrix is minimized, using:
$F_{ml} = log(|\Sigma|) + tr(S\Sigma^-1) - log(|S|) - p$
Where tr is the trace of the matrix - the sum of the diagonal elements, and |S| is the determinant of the matrix S.
Notice that if S and $\Sigma$ are identical, then $F_{ml}$ is equal to zero.
(You can add means to that equation too, if you have them, but it's not necessary to understand it.)
A very handy feature of $F$ is that if you multiply it by $N - 1$ it is chi-square distributed.
I agree with you that it is worth the effort of trying to understand these. If you want to understand this sort of thing more, Bollen's (1989) text Structural Equations with Latent Variables does a good job. If you want to get to the origins, Joreskog's 1969 paper [A General Approach to Confirmatory Factor Analysis][1] is where (I think) this was first published. I wrote a paper, quite some time ago, which explained how to program a simple confirmatory factor model in MS Excel, it's called (imaginatively) Confirmatory Factor Analysis Using Microsoft Excel.
