Closed CarmenTamayo closed 5 months ago
It's this way because EpiNow2 at the moment only accepts: gamma, lognormal, or non parametric distributions:
https://epiforecasts.io/EpiNow2/reference/dist_spec.html
Using non-parametric would work in all situations but I suspect it has its downsides if the distribution is actually known.
Thanks Hugo, so regarding the code for this chunk, it is okay for me to remove the hard-coded gamma distribution and change it to a generic version to account for all distributions that are accounted for by EpiNow2?
From a statistical point of view, the most robust approach would be to pass gamma and lognormal as is and pass other distributions as non-parametric.
cc @sbfnk for confirmation.
Using non-parametric would work in all situations but I suspect it has its downsides if the distribution is actually known.
I'm not sure there is such a downside if the parameters have no uncertainty and the distribution id discrete (or discretised) and truncated - in this case even if passing a probability distribution with parameters it would be converted to a pmf by EpiNow2 before passing to the stan model.
To be sure we're on the same page:
I'm not sure there is such a downside if the parameters have no uncertainty and the distribution id discrete (or discretised) and truncated
Agreed on this. But there are still benefits to passing gamma and lognormal as is, without discretizing them, aren't they?
@Bisaloo @sbfnk following up on this issue- what should I then include in the .rmd chunk? at the moment I understand it's taking whichever distribution from epiparameter
and converting it into a gamma distribution so that it can be used by EpiNow2
Something like the following pseudo-code:
prepare_epinow2_gt <- function(si) {
if (family(si) %in% c("lognormal", "gamma")) { # dists supported by EpiNow2
dist_spec(si_mean, si_sd, distribution = family(si))
} else {
dist_spec(pmf = si$prob_dist$d(si_x))
}
}
generation_time <- prepare_epinow2_gt(si)
In English: if we use a distribution supported out of the box by EpiNow2, we pass it as is. If we are using a distribution not supported by EpiNow2, we pass it as an empirical pmf.
There's not actually a particular benefit to passing the distributional parameters to EpiNow2 except that you might get a more appropriate discretisation (taking into account that it's a delay censored at both ends). Apart from that, if there is no uncertainty in the distributional parameters it's fine to just pass the pmf.
Thanks!
This simplifies our problem a lot then. Let's always pass the pmf directly so we don't have to special case lognormal and gamma distributions.
Thank you both, this is now resolved so I'm closing the issue
Currently the .rmd chunk that uses EpiNow2 for the estimation of Rt of the transmissibility report is fixed for a gamma distribution:
# Approximate serial interval with gamma distribution since this is what EpiNow2 will use for generation_time
si_gamma <- epiparameter::extract_param( type = "range", values = c(median(si$r(1e3)), min(si$r(1e3)), max(si$r(1e3))), distribution = "gamma", samples = 1e3 ) si_gamma <- epiparameter::gamma_shapescale2meansd(si_gamma[[1]], si_gamma[[2]])
I imagine this is because the previous version of the template was assuming a gamma distribution, but since we agreed that this was hard coded when it shouldn't be to allow for flexibility, the rmd chunk should also be changed to take the distribution from the params list.
This change would be included on PR #100 to update epiparameter usage