Error with Bayesian workflow for disease transmission tutorial

I’m trying to follow along with Bayesian workflow for disease transmission modeling in Stan, but unfortunately I can’t get the example to run. I’ve used exactly the code provided in the tutorial with no alterations, but I get the error

[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done

I found this, which seemed to suggest the error could be within the negative binomial function. But the suggested fix doesn’t appear to work for me. Any thoughts?

Hi Ian. I’m unfamiliar with rStan but just by your description alone I assume the problem arises when you’re trying to compile the Stan model. Have you come across this by any chance:

Also, just to confirm, did you save the model in “sir_negbin.stan” as suggested in the source and then had the problem when you run the lines below?

model <- stan_model("sir_negbin.stan")
fit_sir_negbin <- sampling(model,
                data = data_sir,
                iter = niter,
                chains = 4)
1 Like

@charlesm93

Yep, that’s right where I have the problem. I’ve noticed if I comment out the line

cases ~ neg_binomial_2(col(to_matrix(y), 2), phi);

within the “sir_negbin.stan” file I don’t have an issue

I’ve solved the issue, in case anybody runs into this in the future.
I can’t believe I didn’t try this earlier, but I hadn’t installed the latest release of R (version 4.0.2 ). I did that and reinstalled rstan, and now everything is working.

2 Likes