diff --git a/R/disease_progression.R b/R/disease_progression.R index d9ac11e4..9267adf5 100644 --- a/R/disease_progression.R +++ b/R/disease_progression.R @@ -22,7 +22,7 @@ create_progression_process <- function( state, from_state, to_state, - rate, + prob, infectivity, new_infectivity ) { @@ -31,13 +31,13 @@ create_progression_process <- function( # Retrieve the indices of all individuals in the to_move state: index <- state$get_index_of(from_state) - # If the length of rate is greater than 1 (when it's a variable): - if (inherits(rate, "DoubleVariable")) { - rate <- rate$get_values(index) + # If function receives a vector transition probabilities rather than a single value: + if (length(prob) > 1) { + prob <- prob[index$to_vector()] } - # Sample the individuals to be moved into a new Bitset using the transition rate(s): - to_move <- index$sample(1/rate) + # Sample the individuals to be moved into a new Bitset using the transition probabilities: + to_move <- index$sample(prob) # Update the infection status of those individuals who are moving: update_infection( @@ -52,12 +52,12 @@ create_progression_process <- function( create_asymptomatic_progression_process <- function( state, - rate, + prob, variables, parameters ) { function(timestep) { - to_move <- state$get_index_of('D')$sample(1/rate) + to_move <- state$get_index_of('D')$sample(prob) update_to_asymptomatic_infection( variables, parameters, diff --git a/R/processes.R b/R/processes.R index 12f8c3db..2193a40e 100644 --- a/R/processes.R +++ b/R/processes.R @@ -84,7 +84,7 @@ create_processes <- function( ), create_asymptomatic_progression_process( variables$state, - parameters$dd, + 1 - exp(-1/parameters$dd), variables, parameters ), @@ -92,7 +92,7 @@ create_processes <- function( variables$state, 'A', 'U', - parameters$da, + 1 - exp(-1/parameters$da), variables$infectivity, parameters$cu ), @@ -100,7 +100,7 @@ create_processes <- function( variables$state, 'U', 'S', - parameters$du, + 1 - exp(-1/parameters$du), variables$infectivity, 0 ) @@ -109,16 +109,13 @@ create_processes <- function( # ======================= # Antimalarial Resistance # ======================= - # Add an a new process which governs the transition from Tr to S when - # antimalarial resistance is simulated. The rate of transition switches - # from a parameter to a variable when antimalarial resistance == TRUE. # Assign the dt input to a separate object with the default single parameter value: dt_input <- parameters$dt # If antimalarial resistance is switched on, assign dt variable values to the if(parameters$antimalarial_resistance) { - dt_input <- variables$dt + dt_input <- variables$dt$get_values() } # Create the progression process for Tr --> S specifying dt_input as the rate: @@ -128,7 +125,7 @@ create_processes <- function( variables$state, 'Tr', 'S', - dt_input, + 1 - exp(-1/dt_input), variables$infectivity, 0 )