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)