# Error when do bernoulli-logit and categorical_logit

It always shows that no matches for : available argument signatures fir categorical_logit(bernoulli-logit): real return type required for probability function. What does it means?

``````

data {
int<lower=0> N;
int<lower=0> P;
int<lower=0> p1;
int<lower=0> p2;
int<lower=0> p3;

real Y[N];
real X[N];
matrix[N,P] M1;
matrix[N,p3] Mc;
int  contm[p1];
int  binm[p2];

}
parameters {

real alpha0[p1];
real alpha1[p1];
real alpha0_b[p2];
real alpha1_b[p2];
real alpha0_c[p3];
real alpha1_c[p3];

real beta0;
vector[P] beta;
real c;
real<lower=0> sigma1[p1];
real<lower=0> sigma2;

}

model {
matrix[N,p1] mu_M1;
matrix[N,p2] mu_M1_b;
matrix[N,p3] mu_Mc;

vector[N] mu_Y;

for (i in 1:N){
mu_Y[i]= beta0 + c*X[i] + dot_product(beta,M1[i,]);
Y[i] ~ normal(mu_Y[i],sigma2);
for (j in 1:p1){

mu_M1[i,j]=alpha0[j]+alpha1[j]*X[i];
M1[i,contm[j]] ~ normal(mu_M1[i,j],sigma1[j]);
}

for (k in 1:p2){

mu_M1_b[i,k] = alpha0_b[k]+alpha1_b[k]*X[i];
M1[i,binm[k]]~bernoulli_logit(mu_M1_b[i,k]);
}

for (k in 1:p3){

mu_Mc[i,k]=alpha0_c[k]+alpha1_c[k]*X[i];
Mc[i,k] ~ categorical_logit(mu_Mc[i,k]);
}

}

alpha0[1:p1]~normal(0,1);
alpha1[1:p1]~normal(0,1);
alpha0_b[1:p2]~normal(0,1);
alpha1_b[1:P2]~normal(0,1);
alpha0_c[1:p3]~normal(0,1);
alpha1_c[1:P3]~normal(0,1);

sigma1[1:p1]~gamma(1,0.1);
sigma2~gamma(1,0.1);

c~normal(0,1);
beta0~normal(0,1);
beta[1:P]~normal(0,1);

}

``````

`categorical_logit` and `bernoulli_logit` expect the outcomes to have type `int`, but the inputs have them declared as matrices of `real`. Try changing their declaration to `int`:

``````  int M1[N,P];
int Mc[N,p3];
``````

Thanks. I use this to deal with categorical function, but it still have error

data {
int<lower=0> N;
int<lower=0> N1;
int<lower=0> P;
int<lower=0> p1;
int<lower=0> p2;
int<lower=0> p3;
int<lower=0> cat1;
int<lower=2>cat2[p3];
real Y[N];
int X[N];
matrix[N,P] M1;
int M2[N,P];
int Mc[N,P];
int contm[p1];
int binm[p2];
vector[p3] cat3;

}
parameters {

real alpha0[p1];
real alpha1[p1];
real alpha0_b[p2];
real alpha1_b[p2];
matrix[p3,cat2[p3]] alpha0_c;
matrix[cat1,cat2[p3]] alpha1_c;

real beta0;
vector[P] beta;
real c;
real<lower=0> sigma1[p1];
real<lower=0> sigma2;

}

model {
matrix[N,p1] mu_M1;
matrix[N,p2] mu_M1_b;
real mu_Mc[N,p3,N1];
matrix[N,cat1] sum_Mc;
vector[N] mu_Y;
real mu_Mc00[N,cat1,cat2[p3]];

for (i in 1:N){

``````mu_Y[i]= beta0 + c*X[i] + dot_product(beta,M1[i,]);
Y[i] ~ normal(mu_Y[i],sigma2);
for (j in 1:p1){

mu_M1[i,j]=alpha0[j]+alpha1[j]*X[i];
M1[i,contm[j]] ~ normal(mu_M1[i,j],sigma1[j]);
``````

}

``````   for (k in 1:p2){

mu_M1_b[i,k] = alpha0_b[k]+alpha1_b[k]*X[i];
M2[i,binm[k]]~bernoulli_logit(mu_M1_b[i,k]);
``````

}

`````` for (j in 1:cat1){
mu_Mc[i,j,1] =1;
for (k in 2:cat2[j]){
mu_Mc[i,j,k] =exp(alpha0_c[j,k-1]+alpha1_c[j,k-1]*X[i]);
}
sum_Mc[i,j]=sum(mu_Mc[i,j,1:cat2[j]]);
for (l in 1:cat2[j])
{mu_Mc00[i,j,l] =mu_Mc[i,j,l]/sum_Mc[i,j];}
Mc[i,j]~categorical(mu_Mc00[i,j,1:cat2[j]]);
``````

}

}

Can you copy and paste the full error output?

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:

int ~ categorical(real[ ])

Available argument signatures for categorical:

int ~ categorical(vector)
int[ ] ~ categorical(vector)

## Real return type required for probability function. error in ‘model38b4197e6fec_method1_0608’ at line 74, column 50

``````72:       for (l in 1:cat2[j])
73:       {mu_Mc00[i,j,l] =mu_Mc[i,j,l]/sum_Mc[i,j];}
74:       Mc[i,j]~categorical(mu_Mc00[i,j,1:cat2[j]]);
^
75:    }
``````

Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model ‘method1_0608’ due to the above error.

I think mu_Mc00[i,j,1:cat2[j]] is a vector, why it is a real

You’ve declared `mu_Mc00` as a three-dimensional array of `real`:

``````real mu_Mc00[N,cat1,cat2[p3]];
``````

Try changing it to a two-dimensional array of vectors:

``````vector[cat2[p3]] mu_Mc00[N,cat1];
``````