Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
+ README.md updated
+ New vignette added: Simulation
+ Bug fixes for the simulation
  • Loading branch information
smitdave committed Jan 29, 2024
1 parent 599ec56 commit 3777475
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 120 deletions.
10 changes: 5 additions & 5 deletions R/adult-BQ.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#' @export
adult_dynamics.BQ = function(t, model){
with(model,
with(c(Mpar, Mvars), {
with(c(Mpar, Mvars, terms), {
# compute variables
eggs_t = ova*psiQ*Q
B_t = Mbb %*% B + Mbq %*% Q + Mlb %*% Lambda
Q_t = Mqb %*% B + Mqq %*% Q
# update variables
model$Mvars$B = B_t
model$Mvars$Q = Q_t
model$Mvars$eggs = eggs_t
model$terms$eggs = eggs_t
# return the model
return(model)
}))}
Expand Down Expand Up @@ -82,9 +82,9 @@ init_adult_model.BQ = function(model, M0_opts){
#' @return model, a compound [list]
#' @export
init_adult_model_BQ = function(model, opts=list(), B0=10, Q0=10){with(opts,{
model$Mvars$B = c(B0, model$nb, 1)
model$Mvars$Q = c(Q0, model$nq, 1)
model$Mvars$eggs = c(0, model$nq, 1)
model$Mvars$B = rep(B0, model$nb)[1:model$nb]
model$Mvars$Q = rep(Q0, model$nq)[1:model$nq]
model$Mvars$eggs = rep(0, model$nq)[1:model$nq]
return(model)
})}

Expand Down
6 changes: 3 additions & 3 deletions R/adult-BQS.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
#' @export
adult_dynamics.BQS = function(t, model){
with(model,{
with(c(Mpars, vars$M), {
# compute variables
with(c(Mpars, Mvars, terms), {
eggs_t = ova*psiQ*Q
# compute variables
B_t = Mbb %*% B + Mbq %*% Q + Mbs %*% S + Mbl %*% Lambda
Q_t = Mqb %*% B + Mqq %*% Q + Mqs %*% S
S_t = Msb %*% B + Msq %*% Q + Mss %*% S + Msl %*% Lambda
# update variables
model$Mvars$B = B_t
model$Mvars$Q = Q_t
model$Mvars$S = S_t
model$Mvars$eggs = eggs_t
model$terms$eggs = eggs_t
return(model)
})})
}
Expand Down
22 changes: 11 additions & 11 deletions R/aquatic-basicL.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#'
#' @return the model, a compound [list]
#' @export
aquatic_dynamics.basicL = function(t, model){ with(model,{
survive = pL*exp(-zeta*L)
mature = theta*exp(-xi*L)
model$Lambda = mature*survive*L
Lt = (1-mature)*survive*L
Lt = Lt + eggs
model$L= Lt
return(model)
})}
aquatic_dynamics.basicL = function(t, model){ with(model,
with(c(Lpar, Lvars),{
survive = pL*exp(-zeta*L)
mature = theta*exp(-xi*L)
L_t = (1-mature)*survive*L
model$Lvars$L= L_t + model$terms$eggs
model$terms$Lambda = mature*survive*L
return(model)
}))}

#' Set initial values for the BQ model
#'
Expand All @@ -35,8 +35,8 @@ init_aquatic_model.basicL= function(model, L0_opts){
#' @return the model, a compound [list]
#' @export
init_aquatic_model_basicL = function(model, opts=list(), L0=10){with(opts,{
model$Lvars$L = matrix(L0, model$nq, 1)
model$Lvars$Lambda = matrix(0, model$nq, 1)
model$Lvars$L = rep(L0, model$nq)[1:model$nq]
model$terms$Lambda = rep(0, model$nq)[1:model$nq]
return(model)
})}

Expand Down
2 changes: 1 addition & 1 deletion R/aquatic-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ compute_diffs_L = function(Lvars1, Lvars2){
#' @return the model, a compound [list]
#' @export
init_states_L = function(model){
UseMethod("save_states_L", model$Lpar)
UseMethod("init_states_L", model$Lpar)
}

#' Setup an aquatic model
Expand Down
2 changes: 1 addition & 1 deletion R/plot_points.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plot_points = function(model,
bwts=1, qwts=1, swts=1,
pw=1, max_pt_sz=1, mtl=""){
UseMethod("plot_points", model)
UseMethod("plot_points", model$Mpar)
}

#' Plot point sets for a model for a BQ model
Expand Down
1 change: 1 addition & 0 deletions R/setup_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ setup_model = function(b, q, s=c(),

model$Mvars = list()
model = init_adult_model(model, M0_opts)
model$terms = list()

Lpar = list()
class(Lpar) <- Lname
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# motrap.micro <br><br> **Mo**squito **Tr**ansmitted **P**athogen **Micro**-simulation
# motrap.micro <br><br> **Mo**squito **Tr**ansmitted **P**athogen <br> **Micro**-simulation with Behavioral States

Mosquito movement plays an important role in malaria transmission dynamics and vector control. This software was developed to explore mosquito population dispersal, the spatial dynamics of mosquito populations, and malaria transmission dynamics on *point sets,* which we call *micro-simulation.*
The idea of micro-simulation was described by the late Richard Carter (Carter, 2002)^[Carter R (2002) Spatial simulation of malaria transmission and its control by malaria transmission blocking vaccination. International Journal for Parasitology 32: 1617–1624. doi:10.1016/S0020-7519(02)00190-X].
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ navbar:
href: articles/visualizing_dispersal.html
- text: On Dispersal Matrices
href: articles/basic_dispersal.html
- text: Simulation
href: articles/simulation.html
right:
- icon: fa-github
href: https://github.com/dd-harp/motrap.micro/
Expand Down
16 changes: 11 additions & 5 deletions vignettes/simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
library(viridisLite)
library(knitr)
library(viridis)
library(motrap.micro)
#devtools::load_all()
#library(motrap.micro)
devtools::load_all()

## -----------------------------------------------------------------------------
set.seed(24328)
Expand Down Expand Up @@ -32,9 +32,6 @@ Psi_qq = make_Psi_xx(qq, kFq)
par(mfcol = c(2,2), mar = c(1,2,1,2))
plot_Psi_BQ(bb, qq, Psi_bb, Psi_qb, Psi_bq, Psi_qq)

## ----eval=F-------------------------------------------------------------------
# #devtools::load_all()

## -----------------------------------------------------------------------------
opts_d = list(kFb = kFb, kFq = kFq)
model = setup_model(bb, qq, dispersal_opts=opts_d)
Expand All @@ -48,3 +45,12 @@ names(model$Mpar)
## -----------------------------------------------------------------------------
names(model$Lpar)

## -----------------------------------------------------------------------------
model <- SIM(model)

## ----eval=F, echo=F-----------------------------------------------------------
# devtools::load_all()

## ----fig.height=6, fig.width=6, echo=F----------------------------------------
plot_points(model, bwts = model$states$M$B_t[[201]], qwts= model$states$M$B_t[[201]])

48 changes: 28 additions & 20 deletions vignettes/simulation.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: "Mosquito Behavioral State - Microsimulation"
title: "Simulation"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Mosquito Behavioral State - Microsimulation}
%\VignetteIndexEntry{Simulation}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand All @@ -11,27 +11,19 @@ vignette: >
library(viridisLite)
library(knitr)
library(viridis)
library(motrap.micro)
#devtools::load_all()
#library(motrap.micro)
devtools::load_all()
```

## Introduction

If we want to target vector interventions for malaria spatially, fine-grained spatial simulations can be useful. Fine-grained models are difficult to formulate, but they make it possible to conduct thought experiments to test ideas about measuring mosquito populations, good approximating models describing population regulation, and vector control coverage and effect sizes, particularly in a spatial context.
If we want to target vector interventions for malaria spatially, fine-grained spatial simulations can be useful. Fine-grained models can be difficult to formulate and implement, but they make it possible to conduct thought experiments to test ideas about mosquito populations, such as the robustness of metrics we use to measure mosquito populations, spatial targeting, and spatial aspects of vector control coverage and effect sizes.

This software was designed to implement *microsimulation* models where mosquitoes move among *point sets.* To model mosquito movement, we are interested in mosquito searching behavior for resources. Searching for a resource -- a blood host, or a habitat -- is linked to a *behavioral state* and the end of searching is at a point in space where the resources exist. The software implements a set of models that combine these two ideas that represent important departures from the standard theoretical approach to malaria.

First, the idea of microsimulation was described by the late Richard Carter (Carter, 2002)^[Carter R (2002) Spatial simulation of malaria transmission and its control by malaria transmission blocking vaccination. International Journal for Parasitology 32: 1617–1624. doi:10.1016/S0020-7519(02)00190-X].

Second, a new model of malaria transmission was developed by Arnaud Le Menach, *et al.* (2005)^[Le Menach A, McKenzie FE, Flahault A, Smith DL (2005) The unexpected importance of mosquito oviposition behaviour for malaria: Non-productive larval habitats can be sources for malaria transmission. Malar J. 4: 23, doi:10.1186/1475-2875-4-23]; they formulated a compartmental model that split mosquito populations into both **behavioral states** and **infected states.** The split makes more sense if we think of mosquito dispersal in terms of mosquito behaviors during the blood feeding and egg-laying cycle: mosquitoes are not must moving around at random, they are searching for resources. If mosquitoes must *search* for habitats to lay eggs, and then *search* for a blood host, then the resources on those landscapes will tend to structure movement.

The first paper to combine these two ideas together was in an agent based model published by Weidong Gu and Robert J Novak (2009 a,^[Gu W, Novak RJ (2009). Agent-based modelling of mosquito foraging behaviour for malaria control, Trans R Soc Trop Med Hyg 103: 1105–1112, https://doi.org/10.1016/j.trstmh.2009.01.006] b^[Gu W, Novak RJ (2009). Predicting the impact of insecticide-treated bed nets on malaria transmission: the devil is in the detail. Malar J 8:256, https://doi.org/10.1186/1475-2875-8-256]). A few years later, a rigorous mathematical framework to describe mosquito behavioral state micro-simulation was developed by Alex Perkins, *et al.*, (2013)^[Perkins TA, Scott TW, Le Menach A, Smith DL (2013). Heterogeneity, mixing, and the spatial scales of mosquito-borne pathogen transmission. PLoS Comput Biol 9:e1003327, https://doi.org/10.1371/journal.pcbi.1003540], and an individual-based model,
called MBITES (Mosquito Bout-based and Individual-based Transmission Ecology Simulator),
was developed by Sean Wu, *et al.* (2020)^[Wu SL, Sánchez C HM, Henry JM, Citron DT, ... (2020). Vector bionomics and vectorial capacity as emergent properties of mosquito behaviors and ecology. PLoS Comput Biol 16:e1007446, doi:10.1371/journal.pcbi.1007446]
This software was designed to implement *micro-simulation* models where mosquitoes move among *point sets.* To model mosquito movement, we are interested in mosquito searching behavior for resources. Searching for a resource -- a blood host, or a habitat -- is linked to a *behavioral state* and the end of searching is at a point in space where the resources exist. The software implements a set of models that combine these two ideas that represent important departures from the standard theoretical approach to malaria [(landing page)](https://dd-harp.github.io/motrap.micro/index.html). In the following, we walk through the standard model setup.

***

![**Figure 1:** In microsimulation models, mosquitoes move among point sets. Blood feeding on hosts occurs at a fixed set of locations. Also see Perkins, *et al.* (2013). This figure illustrates some of the key elements: a set of points where mosquitoes feed, *{f},* and habitats where they lay eggs *{l)*. Dispersal among those point sets is determined by two matrices, one that describes dispersal to blood feed, $F$, and another to lay eggs, $L$. The framework also describes exposure to infection by a human population.](DynamicsOnPoints.png)
![**Figure 1:** In microsimulation models, mosquitoes move among point sets. Blood feeding on hosts occurs at a fixed set of locations. The figure, modified from Perkins TA, *et al.* (2013)^[Perkins TA, Scott TW, Le Menach A, Smith DL (2013). Heterogeneity, mixing, and the spatial scales of mosquito-borne pathogen transmission. PLoS Comput Biol 9:e1003327, https://doi.org/10.1371/journal.pcbi.1003540], illustrates some of the key elements: a set of points where mosquitoes feed, *{f},* and habitats where they lay eggs *{l)*. Dispersal among those point sets is determined by two matrices, one that describes dispersal to blood feed, $F$, and another to lay eggs, $L$. The framework also describes exposure to infection by a human population.](DynamicsOnPoints.png)

***

Expand Down Expand Up @@ -78,15 +70,11 @@ plot_Psi_BQ(bb, qq, Psi_bb, Psi_qb, Psi_bq, Psi_qq)
```


### Setting up the `model`
### Setting up a model

To simulate mosquito population dynamics, we need to set up an object that stores all the information. In R, we set up the model as a list. To simulate, each model must fully define a set of parameters and initial values. To streamline the process, we developed a function called `setup_model` that accepts some basic arguments and that returns a fully defined model:


```{r, eval=F}
#devtools::load_all()
```


```{r}
opts_d = list(kFb = kFb, kFq = kFq)
Expand All @@ -105,5 +93,25 @@ names(model$Mpar)
names(model$Lpar)
```

### Solving

We can solve the model and produce output by calling the function `SIM`

```{r}
model <- SIM(model)
```

```{r, eval=F, echo=F}
devtools::load_all()
```

The population densities are highly heterogeneous, even though the habitats and blood feeding sites that are all alike in every way except location.

```{r, fig.height=6, fig.width=6, echo=F}
par(mar = c(1,1,1,1))
plot_points(model, bwts = model$states$M$B_t[[201]], qwts= model$states$M$B_t[[201]], max_pt_sz=2)
```




120 changes: 47 additions & 73 deletions vignettes/simulation.html

Large diffs are not rendered by default.

0 comments on commit 3777475

Please sign in to comment.