Dear all,

I am writing my first stan program, with Rstan interface. In the model below, I intended to declare *d* to be a vector of latent (unobserved) Bernoulli variables. But I keep getting this “Rejecting initial value” error from rstan:

"

Chain 1: Rejecting initial value:

Chain 1: Error evaluating the log probability at the initial value.

Chain 1: Exception: bernoulli_lpmf: n is -2147483648, but must be in the interval [0, 1] (in ‘model33787360159d_RE_model’ at line 23)

"

and eventually

"

Chain 1:

Chain 1: Initialization between (-2, 2) failed after 100 attempts.

Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.

[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”

[1] “error occurred during calling the sampler; sampling not done”

"

```
data {
int N;
int P;
int X[N,P];
}
parameters {
vector[P] a1;
vector[P] a0;
real b1;
real b0;
real<lower=0, upper = 1> prev;
}
model {
matrix[N, P] p;
int d[N];
real z[N];
matrix[N,P] S;
matrix[N,P] C;
for(i in 1:N){
d[i] ~ bernoulli(prev);
z[i] ~ std_normal();
for(j in 1:P){
S[i, j] = Phi(a1[j] + b1*z[i]);
C[i, j] = 1 - Phi(a0[j] + b0*z[i]);
p[i, j] = (S[i, j]^d[i]) * (1 - C[i, j])^(1 - d[i]);
X[i, j] ~ binomial(1, p[i, j]);
}
}
}
```

The dataset I used for now is just a arbitrarily simulated dataset using:

N = 500

P = 5

X = matrix(rbinom(N*P, 1, 0.3), nrow = 500, ncol = 5)

Could anyone point out what went wrong in the model?

Thank you,

Yang