Hey there,
I used three categorical variables in my model (att_1/2/3 below), with 6 further latents, across three time points. As I have binary data for three variables, I used DWLS estimation.
My code is as follows:
riclpm <- '
# Create between factors (random intercepts) for each indicator separately.
####################################
#between part with random intercept#
####################################
#ri = random intercept
risdes_t1 =~ 1*sdes_q1 + 1*sdes_q4 + 1*sdes_q6 + 1*sdes_q8 + 1*sdes_q2 + 1*sdes_q3 + 1*sdes_q5 + 1*sdes_q7
riideation_t1 =~ 1*dssis_q1r + 1*dssis_q2r + 1*dssis_q3r + 1*dssis_q4r
risdes_t2 =~ 1*sdes_q1_2 + 1*sdes_q4_2 + 1*sdes_q6_2 + 1*sdes_q8_2 + 1*sdes_q2_2 + 1*sdes_q3_2 + 1*sdes_q5_2 + 1*sdes_q7_2
riideation_t2 =~ 1*dssis_q1r_2 + 1*dssis_q2r_2 + 1*dssis_q3r_2 + 1*dssis_q4r_2
risdes_t3 =~ 1*sdes_q1_3 + 1*sdes_q4_3 + 1*sdes_q6_3 + 1*sdes_q8_3 + 1*sdes_q2_3 + 1*sdes_q3_3 + 1*sdes_q5_3 + 1*sdes_q7_3
riideation_t3 =~ 1*dssis_q1r_3 + 1*dssis_q2r_3 + 1*dssis_q3r_3 + 1*dssis_q4r_3
##################################
# WITHIN PART: MEASUREMENT MODEL #
##################################
#wf = within factor
#create factor models for each construct at 3 waves
wfsdes_t1 =~ sdes_q1 + sdes_q4 + sdes_q6 + sdes_q8 + sdes_q2 + sdes_q3 + sdes_q5 + sdes_q7
wfideation_t1 =~ dssis_q1r + dssis_q2r + dssis_q3r + dssis_q4r
wfsdes_t2 =~ sdes_q1_2 + sdes_q4_2 + sdes_q6_2 + sdes_q8_2 + sdes_q2_2 + sdes_q3_2 + sdes_q5_2 + sdes_q7_2
wfideation_t2 =~ dssis_q1r_2 + dssis_q2r_2 + dssis_q3r_2 + dssis_q4r_2
wfsdes_t3 =~ sdes_q1_3 + sdes_q4_3 + sdes_q6_3 + sdes_q8_3 + sdes_q2_3 + sdes_q3_3 + sdes_q5_3 + sdes_q7_3
wfideation_t3 =~ dssis_q1r_3 + dssis_q2r_3 + dssis_q3r_3 + dssis_q4r_3
#########################
# WITHIN PART: DYNAMICS #
#########################
# Specify the lagged effects between the within-person centered latent variables.
wfideation_t2 + wfsdes_t2 + att_2 ~ wfideation_t1 + wfsdes_t1 + att_1
wfideation_t3 + wfsdes_t3 + att_3 ~ wfideation_t2 + wf sdes_t2 + att_2
# Estimate the correlations within the same wave.
wfsdes_t1 ~~ wfideation_t1
wfideation_t1 ~~ att_1
wfsdes_t2 ~~ wfideation_t2
wfideation_t2 ~~ att_2
wfsdes_t3 ~~ wfideation_t3
wfideation_t3 ~~ att_3
##########################
# ADDITIONAL CONSTRAINTS #
##########################
# Constrain covariance of the between factors and exogenous within factors to 0.
risdes_t1 + riideation_t1 + risdes_t2 + riideation_t2 + risdes_t3 + riideation_t3 ~~ 0*wfsdes_t1 + 0*wfideation_t1 + 0*att_1
'
# model identification and estimation
modelfit_riclpm <- sem(riclpm, data = clpm_sa_full2, ordered = "att_1", "att_2", "att_3")
summary(modelfit_riclpm, fit.measures = T, standardized = T, rsquare = T)
```
However, I get the following errors:
lavaan WARNING: trouble constructing W matrix; used generalized inverse for A11 submatrixlavaan WARNING:
The variance-covariance matrix of the estimated parameters (vcov)
does not appear to be positive definite! The smallest eigenvalue
(= -8.072969e-12) is smaller than zero. This may be a symptom that
the model is not identified.
lavaan WARNING: some estimated lv variances are negative
I've run the same model without the binary variables (att_), but I get the same errors, so I think it could be mostly due to the three Heywood cases in the model for the latter part of the error block above.
However, I'm struggling to understand the earlier error for 'trouble constructing W matrix' and haven't been able to find much guidance online - can anyone help with this please?
It's very possible that I've also coded my model incorrectly above as I'm very new to this so any critical feedback would be hugely appreciated!
Thanks in advance.