ImperialCollegeLondon / covid19model

Code for modelling estimated deaths and cases for COVID19.
MIT License
944 stars 271 forks source link

Suggestions for Stan code #7

Closed bgoodri closed 4 years ago

bgoodri commented 4 years ago

Stan developer here with a few technical changes to base.stan. If you would like more help with Stan, do not hesitate to ask on https://discourse.mc-stan.org/ . Lots of people there can help you, including some who are epidemiologists (which I am not).

  1. fd27cc9: It is often (but not always) better in terms of effective sample size to utilize the scaling property of the exponential distribution (see the top line of https://en.wikipedia.org/wiki/Exponential_distribution#Related_distributions ) if you are going to put exponential priors on unknowns. So I created vector[M] y_raw; in the parameters block and vector[M] y = tau * y_raw; in the transformed parameters block, which allows me to use a unit-exponential prior on y_raw in the model block and induce less posterior dependence on tau.
  2. f6e4079: I used subindexing to eliminate the inner loop in the likelihood, which won't change anything put how fast it is evaluated
  3. 78290f2: I declared convolution locally inside the for loops in transformed parameters and generated quantities. This is mostly cosmetic but allows you to not store something that is not of interest.