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

Changing create_progression_process() rates to probs #295

Closed
wants to merge 5 commits into from

Conversation

tbreweric
Copy link
Contributor

As raised in the PR #289, the create_progression_process() function (disease_progression.R), which governs the way individuals move between some pairs of states, has an argument rate which is currently passed mean state duration time (e.g. parameters$dd. Within the function, the inverse of this rate argument is used to sample individuals to move between states.

While a fix has been suggested for naming the Bitset$sample() function in the individual package, in the meantime the malariasimulation code has been made clearer by:

  • Changing the name of the rate argument to prob in the create_progression_process() and create_asymptomatic_progression_process() functions.
  • Changing the inputs to the create_progression_process() and create_asymptomatic_progression_process() function calls in create_processes() from the former average residence time (parameters$dd) to the probability 1 - exp(-1/parameters$dd)

…create_processes() function. Changed the input for $sample() in the create_progression_process() and create_asymptomatic_progression_process() functions from 1/rate to rate as they now receive the rate rather than the mean residence time in create_processes.
* Changed the rate argument name to prob in create_progression_process() (disease_progression.R)
* Changed the rate argument name to prob in create_asymptomatic_progression_process() (disease_progression.R)
* Checked all tests pass
@tbreweric tbreweric requested a review from giovannic April 26, 2024 12:44
@tbreweric tbreweric requested a review from pwinskill May 8, 2024 11:32
@tbreweric
Copy link
Contributor Author

I've now fixed (hopefully) the conflicts, so ready for the changes to be reviewed now @giovannic @pwinskill !

@tbreweric
Copy link
Contributor Author

tbreweric commented May 8, 2024

The CMD checks are failing because the new dt_input method we added for slow parasite clearance, where dt_input is a DoubleVariable when parameters$antimalarial_resistance == TRUE doesn't work with the updated input for create_progression_process(), where the rate input has been converted to prob and passed the mean stage durations (e.g. dt / dt_input in the following way: 1 - exp(-1/dt_input).

I think the easiest solution here it so change the lines assigning dt_input from variables when antimalarial_resistance == TRUE from:

if(parameters$antimalarial_resistance) {
    dt_input <- variables$dt
}

where dt_input is a DoubleVariable, to something like the following, where dt_input becomes a vector:

if(parameters$antimalarial_resistance) {
    dt_input <- variables$dt$get_values()
}

dt_input can then be passed to create_progression_process() via the converted 1 - exp(-1/dt_input).

Within create_progression_process(), which now receives a vector of probs rather than a DoubleVariable of average state residence times (e.g. dt_input <- variables$dt), we can make the following changes:

  1. Convert the check from inherits to length() to test whether the function has received a single value of vector of values
  2. Use vector subsetting to retrieve the prob values for individuals in the from the inputprobvector which contains the entire populationsprob`
# If function receives a vector transition probabilities rather than a single value:
if (length(prob) > 1) {
  prob <- prob[index$to_vector()]
}

This then allows the sampling of individuals to_move to go ahead using the subsetted prob values:

# Sample the individuals to be moved into a new Bitset using the transition probabilities:
to_move <- index$sample(prob)

…to align with the slow parasite clearance updates
@tbreweric
Copy link
Contributor Author

Have implemented the changes suggested above - seems to have solved the CMD check failures.


# 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()
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't dt vary over time?

It appears to me like we have to pass the DoubleVariable so that the disease progression process can calculate probabilities based on dt for that timestep.

@giovannic
Copy link
Member

obsolete

@giovannic giovannic closed this Sep 30, 2024
@giovannic giovannic deleted the bug/progression_process_rates branch September 30, 2024 12:12
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.

2 participants