I am trying to convert Jags model to stan model.
Jags:
model{
for (i in 1:n){
theta[i] ~ dbeta(u*s, s-u*s)
y[i] ~ dbin(theta[i],N[i])
}
u ~ dunif(0,1)
s ~ dlnorm(4,0.25)
}
stan:
data {
int<lower=0> J;
int y[J];
int N[J];
}
parameters {
real<lower=0, upper=1> u;
real<lower=0> s;
vector[J] theta;
}
model {
s ~ lognormal(4,2);
theta ~ beta(s*u, s*(1-u));
y ~ binomial(N, theta);
}
But when I run it, it returns message as follow:
Chain 1: Rejecting initial value: Chain 1: Error evaluating the log probability at the initial value. Chain 1: Exception: beta_lpdf: Random variable[4] is -1.58608, but must be >= 0! (in 'model29e45483bba0_model' at line 18)
What could generate negative value in this model?