Help from converting from Mplus code to Stan code

One possibility would be to use blavaan for this, which uses Stan under the hood. You might be able to use mplus2lavaan() from the lavaan package to translate your model to lavaan, then pass the lavaan model to blavaan.

Or, if you wanted to do it directly in blavaan: assuming that A1-A3 are either binary or ordinal (as opposed to >2 unordered categories, which are not supported), you could do something like

m1 <- ' A =~ A1 + A2 + A3
        B =~ B1 + B2 + B3
        B1 ~~ A2
        B2 ~~ A3 '
fit <- bcfa(m1, data = mydata, ordered = paste0("A", 1:3))

Possibly with an extra line to specify that the correlation between A and B is 0 (if desired, or it is possibly required to identify the model).

The underlying Stan code is general and not tailored to your model, so not best for learning Stan. It would be worth looking at brms as well, see this thread.

1 Like