epiverse-trace / episoap

[Not published - under active development] A Store of Outbreak Analytics Pipelines Provided as Rmarkdown Report Templates
https://epiverse-trace.github.io/episoap/
Other
4 stars 2 forks source link

Distributions in Rt estimation using {EpiNow2} #113

Closed CarmenTamayo closed 5 months ago

CarmenTamayo commented 6 months ago

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

Bisaloo commented 6 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.

CarmenTamayo commented 6 months ago

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?

Bisaloo commented 6 months ago

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.

sbfnk commented 6 months ago

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.

Bisaloo commented 6 months ago

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?

CarmenTamayo commented 5 months ago

@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

Bisaloo commented 5 months ago

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.

sbfnk commented 5 months ago

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.

Bisaloo commented 5 months ago

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.

CarmenTamayo commented 5 months ago

Thank you both, this is now resolved so I'm closing the issue