Hi,
I am having trouble with reproducing the log likelihood of a saturated path model.
Here is the code I used to fit a very simple saturated path model, and to extract the log-likelihood:
model_temp <- '
x1 ~ x2 + x3
'
fit_temp <- sem(model = model_temp, data = data)
summary(fit_temp)
S <- lavInspect(fit_temp, "obs")$cov # sample covariance matrix
Sigma <- lavInspect(fit_temp, "cov.ov") # model implied covariance matrix
logLik(fit_temp)
- n / 2 * (nrow(S) * log(2 * pi) + log(det(Sigma)) + nrow(S))
- n / 2 * log(det(Sigma)) - n / 2 * sum(diag(S %*% solve(Sigma))) - n / 2 * nrow(S) * log(2 * pi)
I was expecting to get exactly the same value from logLik(fit_temp) and the manual way of calculating the log-likelihood. Is lavaan calculating the log-likelihood differently for a saturated path model?