Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distributions in Rt estimation using {EpiNow2} #113

Closed
CarmenTamayo opened this issue Dec 8, 2023 · 10 comments
Closed

Distributions in Rt estimation using {EpiNow2} #113

CarmenTamayo opened this issue Dec 8, 2023 · 10 comments

Comments

@CarmenTamayo
Copy link
Contributor

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
Copy link
Member

Bisaloo commented Dec 8, 2023

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
Copy link
Contributor Author

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
Copy link
Member

Bisaloo commented Dec 11, 2023

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
Copy link

sbfnk commented Dec 15, 2023

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
Copy link
Member

Bisaloo commented Dec 19, 2023

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
Copy link
Contributor Author

@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
Copy link
Member

Bisaloo commented Jan 9, 2024

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
Copy link

sbfnk commented Jan 24, 2024

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
Copy link
Member

Bisaloo commented Jan 24, 2024

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants