Multinomial logit in rstan

I am new in Stan and i want to make a multinomial baseline logit in RStan but i don’t know how to pass the vectors in R.For example N will be calculated by Stan or i have to say it?The explanatory variables X_{i} how i can pass them to Stan?The Y categories the same.Can someone help me?

f2 = 
"data { int K;
  int N;
  int D;
  int y[N];
  matrix[N, D] x;
parameters {
  matrix[D, K] beta;
model {
  matrix[N, K] x_beta = x * beta;
  to_vector(beta) ~ normal(0, 5);
  for (n in 1:N)
    y[n] ~ categorical_logit(x_beta[n]');
race   = gl(2,2,labels   = c("white","black"));race
gender = gl(2,1,labels = c("female","male"));gender
y1     = c(371,250,64,25)
y2     = c(49,45,9,5)
y3     = c(74,71,15,13)
afterlife = data.frame(race,gender,y1,y2,y3)
y = c(afterlife$y1,afterlife$y2,afterlife$y3)
data2 = list(K,D,x,y)
fit <- stan(model_name = f3, data=data2,
            chains=4, iter=500)

You have to pass that in as data. By defining N as an integer in the data block, you are telling Stan you’ll pass that in.

If they just numbers and a matrix, you should be able to pass those directly in (that’s how the model defines the x variable at least).

Encode these as numbers. Stan doesn’t work with strings. So if you have 3 categories, red, blue, and green for instance, you could encode red as 1, blue as 2, and green as 3, and then pass this in as an array of integers.

Stackoverflow probably has some good stuff. This popped up in a Google search: