# Multinomial regression - (trivial?) error I cannot understand

I have this model, N is 36

``````functions{

vector Q_sum_to_zero_QR(int N) {
vector [2*N] Q_r;

for(i in 1:N) {
Q_r[i] = -sqrt((N-i)/(N-i+1.0));
Q_r[i+N] = inv_sqrt((N-i) * (N-i+1));
}
return Q_r;
}

vector sum_to_zero_QR(vector x_raw, vector Q_r) {
int N = num_elements(x_raw) + 1;
vector [N] x;
real x_aux = 0;

for(i in 1:N-1){
x[i] = x_aux + x_raw[i] * Q_r[i];
x_aux = x_aux + x_raw[i] * Q_r[i+N];
}
x[N] = x_aux;
return x;
}
}
data{
int N;
int M;
int y[N,M];
int X[N,2];
}
transformed data{
int C = 2;
vector[2*M] Q_r = Q_sum_to_zero_QR(M);
real x_raw_sigma = inv_sqrt(1 - inv(M));
}
parameters{
vector[M-1] beta_raw[C];
}
transformed parameters{
vector[M] beta[C];
for(c in 1:C)	beta[c] =  sum_to_zero_QR(beta_raw[c], Q_r);

}
model{

for(n in 1:N) y[n] ~ categorical_logit(  beta[1] + X[n,2] *  beta[2] );

for(i in 1:C) beta_raw[i] ~ normal(0, x_raw_sigma);
}

``````

I get the error

``````Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: categorical_logit_lpmf: categorical outcome out of support is 42, but must be in the interval [1, 36]  (in 'model9ccd700459b8_glm_multinomial' at line 67)
``````

What does the `X[,1]` contain?

Have you tried printing out beta values?

1 Like

X[,1] is just a 1s array (intercept) that Iām not using at the moment.

Yes, beta is real array and has length 36 as expected, same as y[n].