i am working with a ZOIB model in cmdstanr
and would like to add predictions to generated quantities.
I’m using the following function for ZOIB
real zero_one_inflated_beta_lpdf(real y, real mu, real phi, real zoi,
real coi) {
row_vector[2] shape = [mu * phi, (1 - mu) * phi];
if (y == 0) {
return bernoulli_lpmf(1 | zoi) + bernoulli_lpmf(0 | coi);
} else if (y == 1) {
return bernoulli_lpmf(1 | zoi) + bernoulli_lpmf(1 | coi);
} else {
return bernoulli_lpmf(0 | zoi) + beta_lpdf(y | shape[1], shape[2]);
}
}
}
For a zero-inflated negative-binomial model, I used this:
for (n in 1 : N) {
zero=bernoulli_logit_rng(zi[n]);
y_pred[n]=(1-zero)*neg_binomial_2_log_rng(mu[n], shape);
}
Is the following a correct adaptation for this ZOIB model?
for (i in 1 : N) {
zero = bernoulli_rng(zoi);
one = bernoulli_rng(coi);
ypred[i] = one ? 1 : (1-zero) * beta_rng(mu[i], phi);
}