Hi everyone, I am trying to build a simple latent class regression. However, my MCMC never converged.

I have one latent class membership model which is determined by covariate X

Pr(C_i = c) = \frac{exp(X\gamma_c)}{\sum exp(X\gamma_c)}

Also, I have an outcome Y is determined by latent class

E(Y_i|C_i=c) = \mu_c

I am trying to estimate \mu_c and \gamma_c jointly using stan. Any suggestion would be greatly appreciated. The problem is not only about label switching when I add the regression part to latent class analysis. The parameter estimation goes crazy to -5000 to 5000 large number.

```
data {
int<lower=1> G; // Number of subjects
int<lower=1> K; // Number of latent classes
vector[G] Y; // Final Outcome
matrix[G, 2] X1; // Design matrix for covarite-latent
matrix[G, 1] X3; // Design matrix for latent-outcome (Intercept)
}
parameters {
matrix[K-1, 2] gamma_raw;
matrix[1, K] mu;
real<lower=0> sigma_Y; // Residual standard deviation
}
transformed parameters {
matrix[G, K] Yhat;
matrix[K, 2] gamma;
matrix[G, K] logits;
row_vector[2] zeros = rep_row_vector(0, 2);
matrix[G, K] prob;
gamma = append_row(zeros, gamma_raw);
logits = X1*gamma';
// prob of latent class
for (g in 1:G) {
prob[g, ] = to_row_vector(softmax(to_vector(logits[g, ])));
}
// mean of Y
Yhat = X3*mu;
}
model {
for (g in 1:G){
real lmix[K];
for (k in 1: K) {
lmix[k] = log(prob[g, k]) + normal_lpdf(Y[g] |Yhat[g,k], sigma_Y);
}
target += log_sum_exp(lmix);
}
}
```