# Hierarchical Probit; bernoulli with transformed parameter

Hi everyone!

I just started to use STAN and have a question about how to set up my parameters in a simple hierarchical probit regression.

I only have one predictor and two parameters (which jointly constitute an alpha parameter) to explain my binary outcome, and I want to let my parameters differ between each of the J individuals (who each made multiple choices) but sample from a common prior distribution.

I compute alpha in a for loop (there is probably a more efficient way) and apply the Bernoulli on the CDF of the individual alphas.

However, I get the following error: “Ill-typed arguments to ‘~’ statement. No distribution ‘bernoulli’ was found with the correct signature.” It seems like I supply (real,real) to bernoulli (I got that from the excellent tool here) whereas bernoulli expects something else.

To me, the error sounds a bit like I’m supplying a tuple of reals, but that shouldn’t be the case here. What do I miss?

Thank you (and apologies for making newbie mistakes)!
N

My model

``````data {
int<lower=1> J; // number of individuals
int<lower=1> N; // number of observations
vector[N] x;    // predictor
vector[N] y;    // outcome
int<lower=1, upper=J> ind[N]; // individual indicator
}
parameters {
vector<lower=0>[J] p1;
vector<lower=0>[J] p2;

real p1_mean;
real p2_mean;

real<lower=0> p1_var;
real<lower=0> p2_var;

}

transformed parameters {
vector[N] alpha;

for (i in 1:N)
alpha[i] = pow(p1[ind[i]], 2)/ (pow(p1[ind[i]], 2) + pow(p2[ind[i]], 2));
}

model {
p1_mean ~ normal(0, 1);
p2_mean ~ normal(0, 1);

p1_var ~ normal(0, 1);
p2_var ~ normal(0, 1);

p1 ~ normal(p1_mean, p1_var);
p2 ~ normal(p2_mean, p2_var);

for (n in 1:N)
y[n] ~ bernoulli(Phi_approx(alpha[ind[n]]));
}
``````

Welcome aboard!

I think the issue may be that the Bernoulli distribution is expecting the outcomes to be integers.

In the data block, you could try replacing
`vector[N] y;`
with
`array[N] int y;`

Let me know if that doesn’t work.

1 Like

Hi! Indeed, that solved the issue! Thanks so much!