Beta-binomial model

The reason you’re running into trouble is that Stan does not admit integer parameters (has to do with differentiability of the target with respect to all parameters in the model).

To get samples from R \sim \text{beta}(A, B); M \mid R \sim \text{binomial}(N_0, R) , this will work:

data{
  int<lower = 0> N0;
  real<lower = 0> A;
  real<lower = 0> B;
}
parameters{
  real<lower = 0.70, upper = 0.95> R;
}
model {
  R ~ beta(A, B);
}
generated quantities{
  int M = binomial_rng(N0, R);
}

image

1 Like