How to fit Latent Class Regression using STAN

The data generation code is really helpful. I think what’s going on here is that the classes are poorly defined (see plot below), so there isn’t much cost only having 1 or 2 classes. So if the sampler starts with, effectively, 2 classes, there won’t be much to pull that third class in.

So from a data perspective, you could try making the classes more distinct, either by shrinking the residual variance or increasing the mean differences. From a model perspective, I think the only solution is to put stronger priors on the coefficients. Both approaches work for me. As a gut-check, you might do a quick Frequentist LCA with 1-, 2-, and 3-class solutions and compare the fits. My guess is that you original data doesn’t actually need 3 classes, which would explain why one class’ parameters are exploding.