Categorical_logit_rng(vector beta)

Hello!

Is there an example using the categorical_logit_rng(vector beta) function in a multinomial logistic regression?

generated quantities {
 int<lower=1,upper=3> y_tilde[N_new];
  for (n in 1:N_new){
   y_tilde[n] = categorical_logit_rng(vector beta);
 }
}

Using softmax(vector x) function instead, helped me out with the predictions.

softmax(vector x)
3 Likes

What error were you getting? I think categorical_logit_beta shouldn’t need an extra softmax (there is one internally).

1 Like

Thanks for replying. I did not have any error message with categorical_logit_rng, I just do not know how to use it correctly and ended up not using it. categorical_logit_rng gives an integer as result, but I wanted to get the probabilities. My first try was following the mathematical formulae — it required a couple of for loops, however. Then, I read about softmax function which does the same math.

2 Likes

Oh yeah that’s right, for probabilities softmax is the thing you want there.

2 Likes

Hi, I am with the same doubt. But couldn’t figure out how to use the softmax function to generate probabilities instead of integers. How the code chunk would be?