Initialization failed for simple multivariate binomial model

Hi everyone,

I’m new to stan syntax and I’m trying to infer the parameter for a simple multidimensional binomial. Here’s my model and an example of data for D = 3 and N = 8

model {
  data {
  int N;
  int D;
  int y[N,D];
}
parameters {
  vector[D] p;
}
model {
    for (d in 1:D)
        y[,d] ~ bernoulli(p[d]);
} 

y =
[[1 0 1]
[1 0 1]
[1 1 1]
[0 0 0]
[1 1 0]
[0 1 1]
[0 1 0]
[0 1 0]]

With D=2, everything works perfectly, but fails with D>2 (Initialization error, even with n_jobs set to 1).
My question is two fold:

  1. Is there a better way to define my model ?
  2. What do you think produces the error ?

Thanks in advance,
AD.

You need to declare constraints in the parameters block, otherwise Stan won’t know p is supposed to be a probability.

parameters {
  vector<lower=0,upper=1>[D] p;
}
2 Likes

Thanks a lot !