It’s neg_binomial_2, not neg_binomial_5 is the thing:
...
model {
//priors
phi ~ normal(0, 1);
pe ~ normal(0, 1);
pie ~ normal(0, 1);
pee ~ normal(0, 1);
beta ~ normal(0.5, 0.9);
mu ~ normal(0.2, 0.55);
betam ~ normal(0, 1);
tau ~ normal(1, 20);
alpha ~ normal(0.1, 0.99);
Ts ~ normal(3, 20);
Ta ~ normal(1, 20);
Tm ~ normal(1, 20);
Ti ~ normal(0.5, 8);
phi_inv ~ exponential(5);
//sampling distribution
//col(matrix x, int n) - The n-th column of matrix x. Here the number of infected people
cases ~ neg_binomial_2(col(to_matrix(y), 5), phii);
}
generated quantities {
real R0 = beta * Ta * (alpha * Ts * (1 - phi) / Ta + mu * (1 - alpha));
real pred_cases[n_days];
pred_cases = neg_binomial_2_rng(col(to_matrix(y), 5), phii);
}
With this the model compiles for me.
I feel like your rstan is not working correctly.
You shouldn’t be getting error messages like this:
Error in close.connection(zz)
You should be getting error messages like:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Probability function must end in _lpdf or _lpmf. Found distribution family = neg_binomial_5 with no corresponding probability function neg_binomial_5_lpdf, neg_binomial_5_lpmf, or neg_binomial_5_log
error in 'model66865f3d2989_sir_negbin' at line 113, column 53
-------------------------------------------------
111: //sampling distribution
112: //col(matrix x, int n) - The n-th column of matrix x. Here the number of infected people
113: cases ~ neg_binomial_5(col(to_matrix(y), 5), phii);
^
114: }
-------------------------------------------------
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'sir_negbin' due to the above error.
If you can, maybe try installing cmdstanr and switch to it? It is an alternative interface to Stan for R: https://mc-stan.org/cmdstanr/
If nothing else, maybe upgrade to R 4.0 and see if things start working? Only do that if you can risk other packages breaking though: R 4.0, rstan, and you
What operating system are you using? Is this Catalina? Or something else?