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

Issue #408: Fit the susceptible population #904

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Issue #408: Fit the susceptible population #904

wants to merge 17 commits into from

Conversation

seabbs
Copy link
Contributor

@seabbs seabbs commented Dec 19, 2024

Description

This PR closes #408 by allowing for fitting the susceptible population using the new distribution interface.

Maybe to do:

  • it does not add a inference unit test but we didn't have one before for susceptibility
  • This doesn't address if we should be reporting the susceptibility adjusted or unadjusted Rt.

Initial submission checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have tested my changes locally (using devtools::test() and devtools::check()).
  • I have added or updated unit tests where necessary.
  • I have updated the documentation if required and rebuilt docs if yes (using devtools::document()).
  • I have followed the established coding standards (and checked using lintr::lint_package()).
  • I have added a news item linked to this PR.

After the initial Pull Request

  • I have reviewed Checks for this PR and addressed any issues as far as I am able.

@seabbs seabbs requested a review from sbfnk December 19, 2024 18:23
@seabbs seabbs enabled auto-merge December 20, 2024 16:49
@seabbs
Copy link
Contributor Author

seabbs commented Dec 20, 2024

Maybe to do:

I am minded not to do any of these unless you feel strongly

Copy link
Contributor

@sbfnk sbfnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice!

  • This doesn't address if we should be reporting the susceptibility adjusted or unadjusted Rt.

We already have a gen_R in generated quantities (for the nonmechanistic model) - so we could in principle model unadj_R and then always generate R in generated quantities?

R/opts.R Outdated Show resolved Hide resolved
inst/stan/functions/infections.stan Outdated Show resolved Hide resolved
@sbfnk
Copy link
Contributor

sbfnk commented Dec 20, 2024

Maybe to do:

I am minded not to do any of these unless you feel strongly

I don't feel strongly - not quite sure what's best to report anyway. Probably worth a new Issue though as we might be calling stuff R when it's not actually R.

This comment was marked as outdated.

R/opts.R Outdated Show resolved Hide resolved
inst/stan/functions/infections.stan Outdated Show resolved Hide resolved
@seabbs

This comment was marked as outdated.

Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if bafef0b is merged into main:

  • ❗🐌default: 20.1s -> 22.5s [+1.1%, +22.44%]
  • ✔️no_delays: 25.1s -> 23.8s [-15.01%, +4.71%]
  • ✔️random_walk: 9.04s -> 13.3s [-32.12%, +126.71%]
  • ✔️stationary: 11.6s -> 13.2s [-10.22%, +38.66%]
  • ✔️uncertain: 34.9s -> 33.9s [-12.84%, +7.14%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@seabbs seabbs requested a review from sbfnk January 10, 2025 16:25
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 6184ab9 is merged into main:

  • ✔️default: 22.1s -> 21s [-19.07%, +8.83%]
  • ✔️no_delays: 25.2s -> 24.6s [-15.87%, +11.05%]
  • ✔️random_walk: 9.17s -> 9.18s [-10.79%, +11.02%]
  • ✔️stationary: 12s -> 13s [-11.45%, +27.35%]
  • ✔️uncertain: 34.5s -> 35.4s [-7.75%, +13.15%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Comment on lines +331 to +332
#' Note that with "forecast", Rt estimates are unadjusted for susceptible
#' depletion but posterior predictions are adjusted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' Note that with "forecast", Rt estimates are unadjusted for susceptible
#' depletion but posterior predictions are adjusted.
#' Note that with "all", Rt estimates are unadjusted for susceptible
#' depletion but posterior predictions of infections and reports are
#' adjusted.

@@ -125,7 +125,7 @@ simulate_infections <- function(estimates, R, initial_infections,
initial_infections = array(log_initial_infections, dim = c(1, 1)),
initial_growth = array(initial_growth, dim = c(1, length(initial_growth))),
R = array(R$R, dim = c(1, nrow(R))),
pop = pop
use_pop = as.integer(pop != Fixed(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be a future issue but I think we want to be able to have susceptible depletion across full simulations, too.

@@ -5,5 +5,5 @@
array[t - seeding_time] int breakpoints; // when do breakpoints occur
int future_fixed; // is underlying future Rt assumed to be fixed
int fixed_from; // Reference date for when Rt estimation should be fixed
int pop; // Initial susceptible population
int use_pop; // use population size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int use_pop; // use population size
int use_pop; // use population size (0 = no; 1 = forecasts; 2 = all)

@@ -2,6 +2,6 @@
array[n, seeding_time > 1 ? 1 : 0] real initial_growth; //initial growth

matrix[n, t - seeding_time] R; // reproduction number
int pop; // susceptible population
int use_pop; // use population size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int use_pop; // use population size
int use_pop; // use population size (0 = no; 1 = forecasts)

cum_infections[1] = sum(infections[1:uot]);
}
// iteratively update infections
for (s in 1:ot) {
infectiousness[s] = update_infectiousness(infections, gt_rev_pmf, uot, s);
if (pop && s > nht) {
if (use_pop == 1 || (use_pop == 2 && s <= nht)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm not still getting the logic. We have:
use_pop == 1: only adjust in forecast
use_pop == 2: adjust across all

So shouldn't this be

Suggested change
if (use_pop == 1 || (use_pop == 2 && s <= nht)) {
if ((use_pop == 1 && s > nht) || use_pop == 2)) {

Comment on lines +35 to +38
expect_warning(
rt_opts(pop = 1000),
"The `pop` argument of `rt_opts()` must be a `<dist_spec>` as of EpiNow2 1.7.0."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect_warning(
rt_opts(pop = 1000),
"The `pop` argument of `rt_opts()` must be a `<dist_spec>` as of EpiNow2 1.7.0."
)
lifecycle::expect_deprecated(
rt_opts(pop = 1000),
"The `pop` argument of `rt_opts\\(\\)` must be a `<dist_spec>` as of EpiNow2 1.7.0."
)

cum_infections[1] = sum(infections[1:uot]);
}
// iteratively update infections
for (s in 1:ot) {
infectiousness[s] = update_infectiousness(infections, gt_rev_pmf, uot, s);
if (pop && s > nht) {
if (use_pop == 1 || (use_pop == 2 && s <= nht)) {
exp_adj_Rt = exp(-R[s] * infectiousness[s] / (pop - cum_infections[nht]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exp_adj_Rt = exp(-R[s] * infectiousness[s] / (pop - cum_infections[nht]));
exp_adj_Rt = exp(-R[s] * infectiousness[s] / (pop - cum_infections[s]));

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

Successfully merging this pull request may close these issues.

Allow for fitting the susceptible population
3 participants