# Request for Multinomial example

Hi,

I cannot find anything in the manual. I have a problem where the respondent allocates 100 points into K outcomes to show relative preferences. The dependent variable is a vector of K entries. Each entry is a count that sums to a constant (which does not need to be the same from row to row).

Basically, the log-likelihood for each row is:

ll = y[1] * log(p[1])+y[2] * log(p[2])+…+y[K] * log(p[K]);

Can someone provide a complete example STAN code? I believe the “multinomial” distribution is the way to go? Thanks in advance!

1 Like

Have you tried:

``y ~ multinomial(p)``
1 Like

y ~ multinomial§

Does it matter how y is declared, as a matrix[N,K] y or a row_vector[K] y[N]?

How does it ensure that p[1] represents Pr(y=1|) for all the allocation to the first outcome?

Thanks!

`int y[N,K]`

And the encoding for `p` is built in and defined in the manual.

For anyone else who thought the N in

was the sum of y1, y2, …, yk from the multinomial distribution in the manual, it isn’t. This example helped me and might help others.

1 Like

Maybe it was a mistake, but when I coded that the first time, I realized the sum of `y` wasn’t a necessary input for the distribution as it’s implicit in the output variable.

Maybe it wasn’t. I just didn’t get it!

I know, that made it worse!

I’m just glad I figured it out myself!

can you share the example ?