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

Function for setting age-structured outputs. #297

Merged
merged 42 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1ba67c0
Documentation updates
giovannic Aug 15, 2022
08b1f62
mixing matrix row sums == 1 error -> warning
htopazian Aug 26, 2022
c5a7bec
Reduce mixed transmission with testing
giovannic Oct 3, 2022
4e14e50
rebase rdt_mixing to time_varying_metapop
htopazian Oct 5, 2022
4b54e80
Reduce mixed transmission with testing
giovannic Oct 3, 2022
4a58966
Remove platform specific build files
giovannic Oct 6, 2022
3236f76
Add new formula for border test and treat:
giovannic Oct 6, 2022
8e759c1
Update documentation for border check model
giovannic Oct 6, 2022
247432c
fixing metapopulation vignette error
htopazian Oct 7, 2022
f3669f5
Change test and treat coefficients
giovannic Oct 13, 2022
1d4f4a2
Update RDT detection model
giovannic Oct 13, 2022
e568127
Fix regression tests
giovannic Oct 13, 2022
0057fda
RDT+
giovannic Oct 13, 2022
a591eb0
Add test case for completely removing transmission
giovannic Oct 14, 2022
ba4bedc
Add asymmetric transmission in mixing:
giovannic Sep 6, 2023
462b0fe
Merge pull request #277 from mrc-ide/feat/metapop_asym
htopazian Apr 9, 2024
610c5cb
Function for setting age-structured outputs for incidence, prevalence…
RJSheppard May 8, 2024
55d83ea
Added immunity parameter info to documentation of epi outputs function.
RJSheppard May 9, 2024
abdcef0
Function for setting age-structured outputs for incidence, prevalence…
RJSheppard May 8, 2024
8786b81
Added immunity parameter info to documentation of epi outputs function.
RJSheppard May 9, 2024
a542d10
Changed age limits back to continuous groups (no discrete age groups …
RJSheppard May 23, 2024
482fc83
Rebased with latest dev branch, merging with detect pcr/lm outputs.
RJSheppard May 23, 2024
c9c90f5
Merged tip with remote counterpart.
RJSheppard May 23, 2024
8f11a06
Merge branch 'dev' into new_epi_outputs_function
RJSheppard May 24, 2024
09a8c3e
Merge branch 'dev' into new_epi_outputs_function
RJSheppard May 24, 2024
5746a6b
Merge branch 'dev' into feat/metapopulation_model
htopazian Jun 6, 2024
b852847
update documentation
htopazian Jun 6, 2024
24a0253
fix metapop vignette
htopazian Jun 6, 2024
3989fdc
Merge branch 'dev' into new_epi_outputs_function
RJSheppard Jun 12, 2024
7bd8c0d
Update R/mixing.R
htopazian Jul 1, 2024
6d34636
Update R/mixing.R
htopazian Jul 1, 2024
06c1e8d
Remove unnecessary gitignore i386
giovannic Jul 3, 2024
91f8270
Export the run_resumable_simulation
plietar Jul 3, 2024
d05b335
Merge pull request #323 from mrc-ide/export_resumable_simulation
plietar Jul 3, 2024
a4f66e2
Merge branch 'dev' into feat/metapopulation_model
giovannic Jul 4, 2024
e51c6bc
Merge pull request #259 from mrc-ide/feat/metapopulation_model
giovannic Jul 4, 2024
b4825c7
Function for setting age-structured outputs for incidence, prevalence…
RJSheppard May 8, 2024
4701748
Added immunity parameter info to documentation of epi outputs function.
RJSheppard May 9, 2024
e004d5b
Changed age limits back to continuous groups (no discrete age groups …
RJSheppard May 23, 2024
65e5899
Rebased with latest dev branch, merging with detect pcr/lm outputs.
RJSheppard May 23, 2024
0ff9f95
Function for setting age-structured outputs for incidence, prevalence…
RJSheppard May 8, 2024
1886755
Merge branch 'new_epi_outputs_function' of github.com:mrc-ide/malaria…
RJSheppard Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export(peak_season_offset)
export(rtss_booster_profile)
export(rtss_profile)
export(run_metapop_simulation)
export(run_resumable_simulation)
export(run_simulation)
export(run_simulation_with_repetitions)
export(set_antimalarial_resistance)
Expand All @@ -24,6 +25,7 @@ export(set_carrying_capacity)
export(set_clinical_treatment)
export(set_demography)
export(set_drugs)
export(set_epi_outputs)
export(set_equilibrium)
export(set_mass_pev)
export(set_mda)
Expand Down
119 changes: 59 additions & 60 deletions R/biting_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
#' @param lagged_infectivity a list of LaggedValue objects with historical sums
#' of infectivity, one for every metapopulation
#' @param lagged_eir a LaggedValue class with historical EIRs
#' @param mixing a vector of mixing coefficients for the lagged_infectivity
#' values (default: 1)
#' @param mixing_fn a function to retrieve the mixed EIR and infectivity based
#' on the other populations
#' @param mixing_index an index for this population's position in the
#' lagged_infectivity list (default: 1)
#' @noRd
create_biting_process <- function(
renderer,
solvers,
models,
variables,
events,
parameters,
lagged_infectivity,
lagged_eir,
mixing = 1,
mixing_index = 1
) {
renderer,
solvers,
models,
variables,
events,
parameters,
lagged_infectivity,
lagged_eir,
mixing_fn = NULL,
mixing_index = 1
) {
function(timestep) {
# Calculate combined EIR
age <- get_age(variables$birth$get_values(), timestep)
Expand All @@ -43,7 +43,7 @@ create_biting_process <- function(
timestep,
lagged_infectivity,
lagged_eir,
mixing,
mixing_fn,
mixing_index
)

Expand All @@ -61,19 +61,19 @@ create_biting_process <- function(

#' @importFrom stats rpois
simulate_bites <- function(
renderer,
solvers,
models,
variables,
events,
age,
parameters,
timestep,
lagged_infectivity,
lagged_eir,
mixing = 1,
mixing_index = 1
) {
renderer,
solvers,
models,
variables,
events,
age,
parameters,
timestep,
lagged_infectivity,
lagged_eir,
mixing_fn = NULL,
mixing_index = 1
) {
bitten_humans <- individual::Bitset$new(parameters$human_population)

human_infectivity <- variables$infectivity$get_values()
Expand Down Expand Up @@ -111,7 +111,7 @@ simulate_bites <- function(
f <- blood_meal_rate(s_i, Z, parameters)
a <- .human_blood_meal_rate(f, s_i, W, parameters)
lambda <- effective_biting_rates(a, .pi, p_bitten)

if (parameters$individual_mosquitoes) {
species_index <- variables$species$get_index_of(
parameters$species[[s_i]]
Expand All @@ -129,16 +129,18 @@ simulate_bites <- function(
}

# store the current population's EIR for later
lagged_eir[[mixing_index]][[s_i]]$save(n_infectious * a, timestep)

# calculated the EIR for this timestep after mixing
species_eir <- sum(
vnapply(
lagged_eir,
function(l) l[[s_i]]$get(timestep - parameters$de)
) * mixing
lagged_eir[[s_i]]$save(
n_infectious * a,
timestep
)


# lagged EIR
if (is.null(mixing_fn)) {
species_eir <- lagged_eir[[s_i]]$get(timestep - parameters$de)
} else {
species_eir <- mixing_fn(timestep=timestep)$eir[[mixing_index, s_i]]
}

renderer$render(paste0('EIR_', species_name), species_eir, timestep)
EIR <- EIR + species_eir
expected_bites <- species_eir * mean(psi)
Expand All @@ -150,16 +152,16 @@ simulate_bites <- function(
)
}
}
infectivity <- vnapply(
lagged_infectivity,
function(l) l$get(timestep - parameters$delay_gam)
)
lagged_infectivity[[mixing_index]]$save(
sum(human_infectivity * .pi),
timestep
)
foim <- calculate_foim(a, infectivity, mixing)

if (is.null(mixing_fn)) {
infectivity <- lagged_infectivity$get(timestep - parameters$delay_gam)
} else {
infectivity <- mixing_fn(timestep=timestep)$inf[[mixing_index]]
}

lagged_infectivity$save(sum(human_infectivity * .pi), timestep)

foim <- calculate_foim(a, infectivity)
renderer$render(paste0('FOIM_', species_name), foim, timestep)
mu <- death_rate(f, W, Z, s_i, parameters)
renderer$render(paste0('mu_', species_name), mu, timestep)
Expand Down Expand Up @@ -237,14 +239,13 @@ calculate_infectious <- function(species, solvers, variables, parameters) {
}

calculate_infectious_individual <- function(
species,
variables,
infectious_index,
adult_index,
species_index,
parameters
) {

species,
variables,
infectious_index,
adult_index,
species_index,
parameters
) {
infectious_index$copy()$and(species_index)$size()
}

Expand Down Expand Up @@ -300,10 +301,8 @@ unique_biting_rate <- function(age, parameters) {
#' @title Calculate the force of infection towards mosquitoes
#'
#' @param a human blood meal rate
#' @param infectivity_sum a vector of sums of infectivity weighted by relative
#' biting rate for each population
#' @param mixing a vector of mixing coefficients for each population
#' @param infectivity_sum the sum of each individual's infectivity
#' @noRd
calculate_foim <- function(a, infectivity_sum, mixing) {
a * sum(infectivity_sum * mixing)
calculate_foim <- function(a, infectivity_sum) {
a * infectivity_sum
}
72 changes: 72 additions & 0 deletions R/mixing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
create_transmission_mixer <- function(
variables,
parameters,
lagged_eir,
lagged_infectivity,
mixing_tt,
export_mixing,
import_mixing,
p_captured_tt,
p_captured,
p_success
) {
function (timestep) {
n_pops <- length(variables)
rdt_positive <- vnapply(
seq_len(n_pops),
function(i) {
rdt_detectable(variables[[i]], parameters[[i]], timestep)
}
)
mix_t <- match_timestep(mixing_tt, timestep)
p_mix_export <- export_mixing[[mix_t]]
p_mix_import <- import_mixing[[mix_t]]
p_captured_t <- p_captured[[match_timestep(p_captured_tt, timestep)]]
n_species <- length(parameters[[1]]$species)
species_eir <- t(vapply(
seq_along(lagged_eir),
function(i) {
vnapply(
lagged_eir[[i]],
function(l) l$get(timestep - parameters[[i]]$de)
)
},
numeric(n_species)
))
if (n_species == 1) {
species_eir <- t(species_eir)
}
inf <- vnapply(
seq_along(lagged_infectivity),
function(i) lagged_infectivity[[i]]$get(timestep - parameters[[i]]$delay_gam)
)

test_and_treat_coeff <- (1 - p_captured_t * rdt_positive * p_success)
diag(test_and_treat_coeff) <- 1

eir <- vapply(
seq_len(n_species),
function(i) {
mixed_eir <- t(species_eir[,i] * p_mix_import)
rowSums(mixed_eir * test_and_treat_coeff)
},
numeric(n_pops)
)

inf <- rowSums(inf * p_mix_export * test_and_treat_coeff)

list(eir = eir, inf = inf)
}
}

# Estimates RDT prevalence from PCR prevalence,
# We assume PCR prevalence is close to the true proportion of infectious people
# in the population
# values take from Wu et al 2015: https://doi.org/10.1038/nature16039
rdt_detectable <- function(variables, parameters, timestep) {
infectious_prev <- variables$state$get_size_of(
c('D', 'A', 'U')) / parameters$human_population
logit_prev <- log(infectious_prev / (1 - infectious_prev))
logit_rdt <- parameters$rdt_intercept + parameters$rdt_coeff * logit_prev
exp(logit_rdt) / (1 + exp(logit_rdt))
}
Loading
Loading