Dear all
I’m trying to model data with a binomial broadened by a mixture of two beta distributions.
Using the stan code below, I get an error Exception: beta_lpdf: Random variable is nan, but must not be nan!
which I believe means that I need to constrain theta. I have not been able to do this with a prior. Is there another way?
Thanks
Alex
data {
int N;
int n[N];
int y[N];
}
parameters {
real<lower=0, upper=1> lambda;
real<lower=0, upper=1> mu1;
real<lower=0, upper=1> rho1;
real<lower=0, upper=1> mu2;
real<lower=0, upper=1> rho2;
}
model {
real theta;
lambda ~ beta(5,5);
mu1 ~ beta(500, 500);
rho1 ~ exponential(1000);
mu2 ~ beta(5, 5);
rho2 ~ exponential(10);
target += log_mix(
lambda,
beta_lpdf(theta | mu1 * (1 - rho1)/rho1, (1 - mu1) * (1 - rho1)/rho1),
beta_lpdf(theta | mu2 * (1 - rho2)/rho2, (1 - mu2) * (1 - rho2)/rho2));
target += binomial_lpmf(y | n, theta);
}