I have a latent class model with 2 latent classes. I want to make a general code for c classes. I am not sure how to do it though - I know I have to use `categorical_lpmf()`

and have made an attempt below but it doesn’t work (gives nonsensical results).

Here is the code snippet:

```
for (n in 1:N) {
vector[n_class] lp;
matrix[n_class, n_tests] y1;
... does stuff with y1 ....
if (n_class == 2) {
lp[1] = sum(y1[1,]) + bernoulli_lpmf(1 | p);
lp[2] = sum(y1[2,]) + bernoulli_lpmf(0 | p);
} else { // > 2 classes
lp = y1 * rep_vector(1, n_tests) + categorical_lpmf(vector_classes | probs_classes); // attempt (doesnt work)
}
log_lik[n] = log_sum_exp(lp);
}
```

EDIT: nevermind I think I got it. I still used `bernoulli_lpmf`

but with a loop over the classes and using each element of `probs_classes`

as the probability.