-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: main
Are you sure you want to change the base?
Changes from all commits
f372ff5
3e30b64
288b424
6b1cb51
c17fdcb
2967e05
86018b1
07064bd
3bc26d4
01f42c9
e21a5f8
101f1c5
27097cb
bafef0b
841d238
1bedd6c
6184ab9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ simulate_infections <- function(estimates, R, initial_infections, | |
CrIs = c(0.2, 0.5, 0.9), | ||
backend = "rstan", | ||
seeding_time = NULL, | ||
pop = 0, ...) { | ||
pop = Fixed(0), ...) { | ||
## deprecated usage | ||
if (!missing(estimates)) { | ||
deprecate_stop( | ||
|
@@ -86,14 +86,14 @@ simulate_infections <- function(estimates, R, initial_infections, | |
assert_numeric(R$R, lower = 0) | ||
assert_numeric(initial_infections, lower = 0) | ||
assert_numeric(day_of_week_effect, lower = 0, null.ok = TRUE) | ||
assert_numeric(pop, lower = 0) | ||
if (!is.null(seeding_time)) { | ||
assert_integerish(seeding_time, lower = 1) | ||
} | ||
assert_class(delays, "delay_opts") | ||
assert_class(truncation, "trunc_opts") | ||
assert_class(obs, "obs_opts") | ||
assert_class(generation_time, "generation_time_opts") | ||
assert_class(pop, "dist_spec") | ||
|
||
## create R for all dates modelled | ||
all_dates <- data.table(date = seq.Date(min(R$date), max(R$date), by = "day")) | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
) | ||
|
||
data <- c(data, create_stan_delays( | ||
|
@@ -179,7 +179,8 @@ simulate_infections <- function(estimates, R, initial_infections, | |
rho = NULL, | ||
R0 = NULL, | ||
frac_obs = obs$scale, | ||
rep_phi = obs$phi | ||
rep_phi = obs$phi, | ||
pop = pop | ||
)) | ||
## set empty params matrix - variable parameters not supported here | ||
data$params <- array(dim = c(1, 0)) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
int<lower = 0> gt_id; // id of generation time |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
int<lower = 0> gt_id; // id of generation time |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,7 +20,7 @@ real update_infectiousness(vector infections, vector gt_rev_pmf, | |||||
// generate infections by using Rt = Rt-1 * sum(reversed generation time pmf * infections) | ||||||
vector generate_infections(vector oR, int uot, vector gt_rev_pmf, | ||||||
array[] real initial_infections, array[] real initial_growth, | ||||||
int pop, int ht, int obs_scale, real frac_obs) { | ||||||
real pop, int use_pop, int ht, int obs_scale, real frac_obs) { | ||||||
// time indices and storage | ||||||
int ot = num_elements(oR); | ||||||
int nht = ot - ht; | ||||||
|
@@ -42,20 +42,20 @@ vector generate_infections(vector oR, int uot, vector gt_rev_pmf, | |||||
} | ||||||
} | ||||||
// calculate cumulative infections | ||||||
if (pop) { | ||||||
if (use_pop) { | ||||||
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)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I'm not still getting the logic. We have: So shouldn't this be
Suggested change
|
||||||
exp_adj_Rt = exp(-R[s] * infectiousness[s] / (pop - cum_infections[nht])); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
exp_adj_Rt = exp_adj_Rt > 1 ? 1 : exp_adj_Rt; | ||||||
infections[s + uot] = (pop - cum_infections[s]) * (1 - exp_adj_Rt); | ||||||
}else{ | ||||||
infections[s + uot] = R[s] * infectiousness[s]; | ||||||
} | ||||||
if (pop && s < ot) { | ||||||
if (use_pop && s < ot) { | ||||||
cum_infections[s + 1] = cum_infections[s] + infections[s + uot]; | ||||||
} | ||||||
} | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.