From a465cc03f8754d4104c742bd68f460e1daa77e68 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 15 Jan 2025 15:41:49 -0800 Subject: [PATCH] fixed through Psi --- DESCRIPTION | 2 +- NAMESPACE | 13 +- R/Psi_matrices.R | 411 +++++++++----------- R/plot_points.R | 8 +- R/viz_options.R | 1 - README.md | 45 ++- _pkgdown.yml | 17 +- man/add_points_q.Rd | 2 +- man/add_points_qq.Rd | 9 +- man/add_points_s.Rd | 2 +- man/add_points_ss.Rd | 4 +- man/plot_Psi.BQ.Rd | 13 - man/plot_Psi.BQS.Rd | 13 - man/plot_Psi.Rd | 13 - man/plot_Psi_BQ.Rd | 33 +- man/{plot_Psi_BQS.Rd => plot_Psi_BQSmod.Rd} | 30 +- man/plot_Psi_BQmod.Rd | 49 +++ man/plot_Psi_bb.Rd | 40 ++ man/plot_Psi_bs.Rd | 43 ++ man/plot_Psi_qb.Rd | 40 ++ man/plot_Psi_qq.Rd | 40 ++ man/plot_Psi_qs.Rd | 43 ++ man/plot_Psi_sb.Rd | 43 ++ man/plot_Psi_sq.Rd | 43 ++ man/plot_Psi_ss.Rd | 43 ++ vignettes/dispersal.Rmd | 78 ++++ vignettes/kernels.R | 47 ++- vignettes/kernels.Rmd | 112 +++++- vignettes/models.R | 25 ++ vignettes/models.Rmd | 41 ++ vignettes/modularity.Rmd | 47 ++- vignettes/point_sets.R | 18 +- vignettes/point_sets.Rmd | 33 +- vignettes/simulation.R | 5 +- vignettes/simulation.Rmd | 5 +- 35 files changed, 1030 insertions(+), 381 deletions(-) delete mode 100644 R/viz_options.R rename man/{plot_Psi_BQS.Rd => plot_Psi_BQSmod.Rd} (79%) create mode 100644 man/plot_Psi_BQmod.Rd create mode 100644 man/plot_Psi_bb.Rd create mode 100644 man/plot_Psi_bs.Rd create mode 100644 man/plot_Psi_qb.Rd create mode 100644 man/plot_Psi_qq.Rd create mode 100644 man/plot_Psi_qs.Rd create mode 100644 man/plot_Psi_sb.Rd create mode 100644 man/plot_Psi_sq.Rd create mode 100644 man/plot_Psi_ss.Rd create mode 100644 vignettes/models.R diff --git a/DESCRIPTION b/DESCRIPTION index 6afc85e..7350ddc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ramp.micro Type: Package -Title: *Mo*squito *Tr*ansmitted *P*athogen *Micro*simulation with Behavioral States +Title: Microsimulation for Mosquito Ecology Version: 0.1.0 Authors@R: c( person("David L.", "Smith", email = "smitdave@uw.edu", role = c("aut","cre"), comment = c(ORCID = "0000-0003-4367-3849")), diff --git a/NAMESPACE b/NAMESPACE index 19161a0..4167c40 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -104,8 +104,17 @@ export(plot_Kbq) export(plot_Kqb) export(plot_Kqq) export(plot_Psi) -export(plot_Psi_BQ) -export(plot_Psi_BQS) +export(plot_Psi_BQSmod) +export(plot_Psi_BQmod) +export(plot_Psi_bb) +export(plot_Psi_bq) +export(plot_Psi_bs) +export(plot_Psi_qb) +export(plot_Psi_qq) +export(plot_Psi_qs) +export(plot_Psi_sb) +export(plot_Psi_sq) +export(plot_Psi_ss) export(plot_convex_hulls) export(plot_dispersal_G) export(plot_dispersal_GG) diff --git a/R/Psi_matrices.R b/R/Psi_matrices.R index 1b3c135..52ada9c 100644 --- a/R/Psi_matrices.R +++ b/R/Psi_matrices.R @@ -71,30 +71,10 @@ plot_Psi = function(model, max_pt_sz=2, #' @export plot_Psi.BQ = function(model, max_pt_sz=2, min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - with(model,{plot_Psi_BQ(b,q,Psi_bb, Psi_qb, Psi_bq, Psi_qq, + with(model,{plot_Psi_BQmod(b,q,Psi_bb, Psi_qb, Psi_bq, Psi_qq, max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac, r=r, arw_lng=arw_lng, lwd=lwd)})} -#' Visualize the one-bout dispersal matrices for a BQS model -#' -#' @param model a model defined as a compound [list] -#' @param max_pt_sz set the maximum cex for points -#' @param min_edge_frac the fraction of the mass to plot -#' @param r the radius of a ring around destination points -#' @param arw_lng the arrow length -#' @param lwd scale the line width -#' -#' @return the model, a compound [list] -#' @export -plot_Psi.BQS = function(model,max_pt_sz=2, - min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - with(model,{plot_Psi_BQS(b,q,s, - Psi_bb, Psi_qb, Psi_sb, - Psi_bq, Psi_qq, Psi_sq, - Psi_bs, Psi_qs, Psi_ss, - max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd) - })} #' Visualize the one-bout dispersal matrices for a BQ model #' @@ -112,43 +92,43 @@ plot_Psi.BQS = function(model,max_pt_sz=2, #' #' @return no visible return value #' @export -plot_Psi_BQ = function(b,q, +plot_Psi_BQmod = function(b, q, Psi_bb, Psi_qb, Psi_bq, Psi_qq, max_pt_sz=2, min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - graphics::par(mfcol = c(2,2), mar = c(2,2,2,2)) - ## b to b - frame_bq(b,q, mtl=expression(Psi[b %<-% b])) - add_points_q(q, max_pt_sz = 0.7) - add_arrows_xx(b, Psi_bb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "tomato") - add_points_bb(b, Psi_bb, max_pt_sz=max_pt_sz) - - ## q to b - frame_bq(b,q, mtl = expression(Psi[b %<-% q])) - add_points_q(q, max_pt_sz = 0.7) - add_arrows_xy(q, b, Psi_bq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="skyblue2") - add_points_b(b, rowSums(Psi_bq), max_pt_sz = max_pt_sz) + graphics::par(mfrow = c(2,2), mar = c(2,2,2,2)) - ## b to q - frame_bq(b, q, mtl = expression(Psi[q %<-% b])) - add_points_b(b, max_pt_sz=0.7) - add_arrows_xy(b, q, Psi_qb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "tomato") - add_points_q(q, rowSums(Psi_qb), max_pt_sz=max_pt_sz) - - ##q to q - frame_bq(b,q, mtl = expression(Psi[q %<-% q])) - add_points_b(b, max_pt_sz=0.7) - add_arrows_xx(q, Psi_qq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr="skyblue2") - add_points_qq(q, Psi_qq, max_pt_sz=max_pt_sz, colA="skyblue") + plot_Psi_bq(b, q, Psi_bq, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_bb(b, q, Psi_bb, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_qb(b, q, Psi_qb, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_qq(b, q, Psi_qq, max_pt_sz, min_edge_frac, r, arw_lng, lwd) return(invisible()) } +#' Visualize the one-bout dispersal matrices for a BQS model +#' +#' @param model a model defined as a compound [list] +#' @param max_pt_sz set the maximum cex for points +#' @param min_edge_frac the fraction of the mass to plot +#' @param r the radius of a ring around destination points +#' @param arw_lng the arrow length +#' @param lwd scale the line width +#' +#' @return the model, a compound [list] +#' @export +plot_Psi.BQS = function(model,max_pt_sz=2, + min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ + with(model,{plot_Psi_BQSmod(b,q,s, + Psi_bb, Psi_qb, Psi_sb, + Psi_bq, Psi_qq, Psi_sq, + Psi_bs, Psi_qs, Psi_ss, + max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac, + r=r, arw_lng=arw_lng, lwd=lwd) + })} + + #' Visualize the one-bout dispersal matrices for a BQS model #' #' @param b blood feeding sites point set @@ -171,138 +151,105 @@ plot_Psi_BQ = function(b,q, #' #' @return no visible return value #' @export -plot_Psi_BQS = function(b,q,s, +plot_Psi_BQSmod = function(b,q,s, Psi_bb, Psi_qb, Psi_sb, Psi_bq, Psi_qq, Psi_sq, Psi_bs, Psi_qs, Psi_ss, max_pt_sz=2, min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ graphics::par(mfcol = c(3,3), mar = c(2,2,2,2)) - ## b to b - frame_bqs(b,q,s, mtl = expression(Psi[b%<-%b])) - add_arrows_xx(b, Psi_bb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "tomato") - add_points_bb(b, Psi_bb, max_pt_sz=max_pt_sz) - - ## q to b - frame_bqs(b, q, s, mtl = expression(Psi[b %<-% q])) - add_points_q(q, max_pt_sz = 0.7) - add_arrows_xy(q, b, Psi_bq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="skyblue2") - add_points_b(b, rowSums(Psi_bq), max_pt_sz = max_pt_sz) - - ## s to b - frame_bqs(b, q, s, mtl = expression(Psi[b %<-% s])) - add_points_s(s, max_pt_sz = 0.7) - add_arrows_xy(s, b, Psi_bs, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="goldenrod") - add_points_b(b, rowSums(Psi_bs), max_pt_sz = max_pt_sz) - - ## b to q - frame_bqs(b, q, s, mtl = expression(Psi[q %<-% b])) - add_points_b(b, max_pt_sz=0.7) - add_arrows_xy(b, q, Psi_qb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "tomato") - add_points_q(q, rowSums(Psi_qb), max_pt_sz=max_pt_sz) - - ##q to q - frame_bqs(b,q,s, mtl = expression(Psi[q%<-%q])) - add_arrows_xx(q, Psi_qq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "skyblue2") - add_points_qq(q, Psi_qq, max_pt_sz=max_pt_sz) - - ## s to q - frame_bqs(b,q,s, mtl = expression(Psi[q %<-% s])) - add_points_s(s, max_pt_sz = 0.7) - add_arrows_xy(s, q, Psi_qs, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="goldenrod") - add_points_q(q, rowSums(Psi_qs), max_pt_sz = max_pt_sz) - - ## b to s - frame_bqs(b, q, s, mtl = expression(Psi[s %<-% b])) - add_points_b(b, max_pt_sz=0.7) - add_arrows_xy(b, s, Psi_sb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "tomato") - add_points_s(s, rowSums(Psi_sb), max_pt_sz=max_pt_sz) - ## q to s - frame_bqs(b, q, s, mtl = expression(Psi[s %<-% q])) - add_points_q(q, max_pt_sz=0.7) - add_arrows_xy(q, s, Psi_sq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "skyblue2") - add_points_s(s, rowSums(Psi_sq), max_pt_sz=max_pt_sz) - - ##s to s - frame_bqs(b,q,s, mtl = expression(Psi[s%<-%s])) - add_arrows_xx(s, Psi_ss, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "goldenrod") - add_points_ss(s, Psi_ss, max_pt_sz=max_pt_sz) + plot_Psi_bb(b, q, Psi_bb, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_bq(b, q, Psi_bq, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_bs(b, q, s, Psi_bs, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_qb(b, q, Psi_qb, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_qq(b, q, Psi_qq, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_qs(b, q, s, Psi_qs, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_sb(b, q, s, Psi_sb, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_sq(b, q, s, Psi_sq, max_pt_sz, min_edge_frac, r, arw_lng, lwd) + plot_Psi_ss(b, q, s, Psi_ss, max_pt_sz, min_edge_frac, r, arw_lng, lwd) return(invisible()) } - -#' Visualize the one-bout dispersal matrices +#' Visualize the one-bout dispersal matrices for a BQ model #' -#' @param model a model defined as a compound [list] +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param Psi_bb one bout dispersal matrix from b to b #' @param max_pt_sz set the maximum cex for points #' @param min_edge_frac the fraction of the mass to plot #' @param r the radius of a ring around destination points #' @param arw_lng the arrow length #' @param lwd scale the line width #' -#' @return the model, a compound [list] +#' @return no visible return value #' @export -plot_Psi = function(model, max_pt_sz=2, - min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - UseMethod("plot_Psi", model) -} +plot_Psi_bb = function(b, q, Psi_bb, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ + ## b to b + frame_bq(b,q, mtl=expression(Psi[b %<-% b])) + add_arrows_xx(b, Psi_bb, min_edge_frac=min_edge_frac, + r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "tomato") + add_points_bb(b, Psi_bb, max_pt_sz=max_pt_sz) + + return(invisible()) +} #' Visualize the one-bout dispersal matrices for a BQ model #' -#' @param model a model defined as a compound [list] +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param Psi_bq one bout dispersal matrix from b to q #' @param max_pt_sz set the maximum cex for points #' @param min_edge_frac the fraction of the mass to plot #' @param r the radius of a ring around destination points #' @param arw_lng the arrow length #' @param lwd scale the line width #' -#' @return the model, a compound [list] +#' @return no visible return value #' @export -plot_Psi.BQ = function(model, max_pt_sz=2, - min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - with(model,{plot_Psi_BQ(b,q,Psi_bb, Psi_qb, Psi_bq, Psi_qq, - max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd)})} +plot_Psi_bq = function(b,q, Psi_bq, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ + frame_bq(b, q, mtl = expression(Psi[b %<-% q])) + add_points_q(q, max_pt_sz = 0.6) + add_arrows_xy(q, b, Psi_bq, min_edge_frac=min_edge_frac, + r=r, arw_lng=arw_lng, lwd=lwd, clr="tomato") + add_points_b(b, rowSums(Psi_bq), max_pt_sz = max_pt_sz) + return(invisible()) +} -#' Visualize the one-bout dispersal matrices for a BQS model +#' Visualize the dispersal matrix to b from s #' -#' @param model a model defined as a compound [list] +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param s sugar feeding sites point set +#' @param Psi_bs one bout dispersal matrix to b from s #' @param max_pt_sz set the maximum cex for points #' @param min_edge_frac the fraction of the mass to plot #' @param r the radius of a ring around destination points #' @param arw_lng the arrow length #' @param lwd scale the line width #' -#' @return the model, a compound [list] +#' @return no visible return value #' @export -plot_Psi.BQS = function(model,max_pt_sz=2, - min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - with(model,{plot_Psi_BQS(b,q,s, - Psi_bb, Psi_qb, Psi_sb, - Psi_bq, Psi_qq, Psi_sq, - Psi_bs, Psi_qs, Psi_ss, - max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd) - })} +plot_Psi_bs = function(b, q, s, Psi_bs, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ + frame_bqs(b, q, s, mtl = expression(Psi[b %<-% s])) + add_points_s(s, max_pt_sz = 0.6) + add_arrows_xy(s, b, Psi_bs, min_edge_frac=min_edge_frac, + r=r, arw_lng=arw_lng, lwd=lwd, clr= "tomato") + add_points_b(b, rowSums(Psi_bs), max_pt_sz = max_pt_sz) + return(invisible()) +} #' Visualize the one-bout dispersal matrices for a BQ model #' #' @param b blood feeding sites point set #' @param q egg laying sites point set -#' @param Psi_bb one bout dispersal matrix from b to b #' @param Psi_qb one bout dispersal matrix from q to b -#' @param Psi_bq one bout dispersal matrix from b to q -#' @param Psi_qq one bout dispersal matrix from q to q #' @param max_pt_sz set the maximum cex for points #' @param min_edge_frac the fraction of the mass to plot #' @param r the radius of a ring around destination points @@ -311,57 +258,25 @@ plot_Psi.BQS = function(model,max_pt_sz=2, #' #' @return no visible return value #' @export -plot_Psi_BQ = function(b,q, - Psi_bb, Psi_qb, - Psi_bq, Psi_qq, +plot_Psi_qb = function(b, q, Psi_qb, max_pt_sz=2, min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){ - graphics::par(mfcol = c(2,2), mar = c(2,2,2,2)) - ## b to b - frame_bq(b,q, mtl=expression(Psi[b %<-% b])) - add_points_q(q, max_pt_sz = 0.7) - add_arrows_xx(b, Psi_bb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "tomato") - add_points_bb(b, Psi_bb, max_pt_sz=max_pt_sz) - - ## q to b - frame_bq(b,q, mtl = expression(Psi[b %<-% q])) - add_points_q(q, max_pt_sz = 0.7) - add_arrows_xy(q, b, Psi_bq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="skyblue2") - add_points_b(b, rowSums(Psi_bq), max_pt_sz = max_pt_sz) ## b to q frame_bq(b, q, mtl = expression(Psi[q %<-% b])) - add_points_b(b, max_pt_sz=0.7) + add_points_b(b, max_pt_sz=0.6) add_arrows_xy(b, q, Psi_qb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "tomato") + r=r, arw_lng=arw_lng, lwd=lwd, clr = "skyblue") add_points_q(q, rowSums(Psi_qb), max_pt_sz=max_pt_sz) - - ##q to q - frame_bq(b,q, mtl = expression(Psi[q %<-% q])) - add_points_b(b, max_pt_sz=0.7) - add_arrows_xx(q, Psi_qq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr="skyblue2") - add_points_qq(q, Psi_qq, max_pt_sz=max_pt_sz, colA="skyblue") return(invisible()) } -#' Visualize the one-bout dispersal matrices for a BQS model +#' Visualize the one-bout dispersal matrices for a BQ model #' #' @param b blood feeding sites point set #' @param q egg laying sites point set -#' @param s sugar feeding sites point set -#' @param Psi_bb one bout dispersal matrix from b to b -#' @param Psi_qb one bout dispersal matrix from q to b -#' @param Psi_sb one bout dispersal matrix from s to b -#' @param Psi_bq one bout dispersal matrix from b to q #' @param Psi_qq one bout dispersal matrix from q to q -#' @param Psi_sq one bout dispersal matrix from s to q -#' @param Psi_bs one bout dispersal matrix from b to s -#' @param Psi_qs one bout dispersal matrix from q to s -#' @param Psi_ss one bout dispersal matrix from s to s #' @param max_pt_sz set the maximum cex for points #' @param min_edge_frac the fraction of the mass to plot #' @param r the radius of a ring around destination points @@ -370,71 +285,121 @@ plot_Psi_BQ = function(b,q, #' #' @return no visible return value #' @export -plot_Psi_BQS = function(b,q,s, - Psi_bb, Psi_qb, Psi_sb, - Psi_bq, Psi_qq, Psi_sq, - Psi_bs, Psi_qs, Psi_ss, - max_pt_sz=2, min_edge_frac = 0.01, - r=.01, arw_lng=0.05, lwd=2){ - graphics::par(mfcol = c(3,3), mar = c(2,2,2,2)) - ## b to b - frame_bqs(b,q,s, mtl = expression(Psi[b%<-%b])) - add_arrows_xx(b, Psi_bb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "tomato") - add_points_bb(b, Psi_bb, max_pt_sz=max_pt_sz) - - ## q to b - frame_bqs(b, q, s, mtl = expression(Psi[b %<-% q])) - add_points_q(q, max_pt_sz = 0.7) - add_arrows_xy(q, b, Psi_bq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="skyblue2") - add_points_b(b, rowSums(Psi_bq), max_pt_sz = max_pt_sz) - - ## s to b - frame_bqs(b, q, s, mtl = expression(Psi[b %<-% s])) - add_points_s(s, max_pt_sz = 0.7) - add_arrows_xy(s, b, Psi_bs, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="goldenrod") - add_points_b(b, rowSums(Psi_bs), max_pt_sz = max_pt_sz) - - ## b to q - frame_bqs(b, q, s, mtl = expression(Psi[q %<-% b])) - add_points_b(b, max_pt_sz=0.7) - add_arrows_xy(b, q, Psi_qb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "tomato") - add_points_q(q, rowSums(Psi_qb), max_pt_sz=max_pt_sz) - +plot_Psi_qq = function(b, q, Psi_qq, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ ##q to q - frame_bqs(b,q,s, mtl = expression(Psi[q%<-%q])) + frame_bq(b, q, mtl = expression(Psi[q %<-% q])) add_arrows_xx(q, Psi_qq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "skyblue2") + r=r, arw_lng=arw_lng, lwd=lwd, arw_clr="skyblue") add_points_qq(q, Psi_qq, max_pt_sz=max_pt_sz) - ## s to q - frame_bqs(b,q,s, mtl = expression(Psi[q %<-% s])) - add_points_s(s, max_pt_sz = 0.7) + return(invisible()) +} + +#' Visualize the one-bout dispersal matrices for a BQ model +#' +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param s sugar feeding sites point set +#' @param Psi_qs one bout dispersal matrix to q from s +#' @param max_pt_sz set the maximum cex for points +#' @param min_edge_frac the fraction of the mass to plot +#' @param r the radius of a ring around destination points +#' @param arw_lng the arrow length +#' @param lwd scale the line width +#' +#' @return no visible return value +#' @export +plot_Psi_qs = function(b, q, s, Psi_qs, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ + + frame_bqs(b, q, s, mtl = expression(Psi[q %<-% s])) + add_points_s(s, max_pt_sz=0.6) add_arrows_xy(s, q, Psi_qs, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr="goldenrod") - add_points_q(q, rowSums(Psi_qs), max_pt_sz = max_pt_sz) + r=r, arw_lng=arw_lng, lwd=lwd, clr = "skyblue") + add_points_q(q, rowSums(Psi_qs), max_pt_sz=max_pt_sz) + return(invisible()) +} + + +#' Visualize the one-bout dispersal matrices for a BQ model +#' +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param s sugar feeding sites point set +#' @param Psi_sb one bout dispersal matrix to s from b +#' @param max_pt_sz set the maximum cex for points +#' @param min_edge_frac the fraction of the mass to plot +#' @param r the radius of a ring around destination points +#' @param arw_lng the arrow length +#' @param lwd scale the line width +#' +#' @return no visible return value +#' @export +plot_Psi_sb = function(b, q, s, Psi_sb, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ - ## b to s frame_bqs(b, q, s, mtl = expression(Psi[s %<-% b])) - add_points_b(b, max_pt_sz=0.7) + add_points_b(b, max_pt_sz=0.6) add_arrows_xy(b, s, Psi_sb, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "tomato") + r=r, arw_lng=arw_lng, lwd=lwd, clr = "olivedrab1") add_points_s(s, rowSums(Psi_sb), max_pt_sz=max_pt_sz) + return(invisible()) +} + +#' Visualize the one-bout dispersal matrices for a BQ model +#' +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param s sugar feeding sites point set +#' @param Psi_sq one bout dispersal matrix to s from q +#' @param max_pt_sz set the maximum cex for points +#' @param min_edge_frac the fraction of the mass to plot +#' @param r the radius of a ring around destination points +#' @param arw_lng the arrow length +#' @param lwd scale the line width +#' +#' @return no visible return value +#' @export +plot_Psi_sq = function(b, q, s, Psi_sq, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ - ## q to s frame_bqs(b, q, s, mtl = expression(Psi[s %<-% q])) - add_points_q(q, max_pt_sz=0.7) + add_points_q(q, max_pt_sz=0.6) add_arrows_xy(q, s, Psi_sq, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, clr = "skyblue2") + r=r, arw_lng=arw_lng, lwd=lwd, clr = "olivedrab1") add_points_s(s, rowSums(Psi_sq), max_pt_sz=max_pt_sz) + return(invisible()) +} + +#' Visualize the one-bout dispersal matrices for a Bs model +#' +#' @param b blood feeding sites point set +#' @param q egg laying sites point set +#' @param s sugar feeding sites point set +#' @param Psi_ss one bout dispersal matrix from s to s +#' @param max_pt_sz set the maximum cex for points +#' @param min_edge_frac the fraction of the mass to plot +#' @param r the radius of a ring around destination points +#' @param arw_lng the arrow length +#' @param lwd scale the line width +#' +#' @return no visible return value +#' @export +plot_Psi_ss = function(b, q, s, Psi_ss, + max_pt_sz=2, min_edge_frac = 0.01, + r=.01, arw_lng=0.05, lwd=2){ ##s to s - frame_bqs(b,q,s, mtl = expression(Psi[s%<-%s])) + frame_bqs(b, q, s, mtl = expression(Psi[s %<-% s])) add_arrows_xx(s, Psi_ss, min_edge_frac=min_edge_frac, - r=r, arw_lng=arw_lng, lwd=lwd, arw_clr = "goldenrod") + r=r, arw_lng=arw_lng, lwd=lwd, arw_clr="olivedrab1") add_points_ss(s, Psi_ss, max_pt_sz=max_pt_sz) + return(invisible()) } + diff --git a/R/plot_points.R b/R/plot_points.R index 3396e00..e8d8d59 100644 --- a/R/plot_points.R +++ b/R/plot_points.R @@ -160,7 +160,7 @@ add_points_b = function(b, wts=1, pw=1, max_pt_sz=1, clr="#fe5f55CC"){ #' #' @return invisible(NULL) #' @export -add_points_q = function(q, wts=1, pw=1, max_pt_sz=1, clr="#4361eeCC"){ +add_points_q = function(q, wts=1, pw=1, max_pt_sz=1, clr="skyblue"){ graphics::points(q, col=clr, pch=19, cex=max_pt_sz*wts^pw/max(wts^pw)) return(invisible()) } @@ -175,7 +175,7 @@ add_points_q = function(q, wts=1, pw=1, max_pt_sz=1, clr="#4361eeCC"){ #' #' @return invisible(NULL) #' @export -add_points_s = function(s, wts=1, pw=1, max_pt_sz=1, clr="#ff4800CC"){ +add_points_s = function(s, wts=1, pw=1, max_pt_sz=1, clr="olivedrab2"){ graphics::points(s, col=clr, pch=17, cex=max_pt_sz*wts^pw/max(wts^pw)) return(invisible()) } @@ -209,7 +209,7 @@ add_points_bb = function(b, M, pw=1, max_pt_sz=2, colA="#cc444b66", colB="#cc444 #' #' @return invisible(NULL) #' @export -add_points_qq = function(q, M, pw=1, max_pt_sz=2, colA="#4e148c66", colB="#4e148cCC"){ +add_points_qq = function(q, M, pw=1, max_pt_sz=2, colA="skyblue", colB="skyblue3"){ add_points_q(q, as.vector(rowSums(M)), pw, max_pt_sz, colA) diag(M) <- 0 add_points_q(q, as.vector(rowSums(M)), pw, max_pt_sz, colB) @@ -227,7 +227,7 @@ add_points_qq = function(q, M, pw=1, max_pt_sz=2, colA="#4e148c66", colB="#4e148 #' #' @return invisible(NULL) #' @export -add_points_ss = function(s, M, pw=1, max_pt_sz=2, colA="#8bc74266", colB="#8bc742CC"){ +add_points_ss = function(s, M, pw=1, max_pt_sz=2, colA="olivedrab2", colB="olivedrab3"){ add_points_s(s, as.vector(rowSums(M)), pw, max_pt_sz, colA) diag(M) <- 0 add_points_s(s, as.vector(rowSums(M)), pw, max_pt_sz, colB) diff --git a/R/viz_options.R b/R/viz_options.R deleted file mode 100644 index 8b13789..0000000 --- a/R/viz_options.R +++ /dev/null @@ -1 +0,0 @@ - diff --git a/README.md b/README.md index 9d3df1a..5cba44f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,41 @@ -# ramp.micro

**Mo**squito **Tr**ansmitted **P**athogen
**Micro**-simulation with Behavioral States +# **`ramp.micro`** +# Microsimulation for Mosquito Ecology & Pathogen Transmission -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]. +This software was developed to lower the costs of building and analyzing micro-simulation models for mosquito ecology and for mosquito-borne pathogen transmission dynamics and control. +It is a GitHub R Package that can be installed using `devtools` by running this code from an R prompt: -This software implements *behavioral state models,* which are a natural complement to micro-simulation. The basic premise is that mosquitoes are typically *searching* for a resource, not wandering around aimlessly. -Over their lives, mosquito behaviors are determined by a physiological state and its associated behavioral algorithm(s). -The search algorithms have evolved to accomplish a task that increases a mosquito's fitness. To survive and lay eggs, mosquitoes must find resources: mates, vertebrate hosts to blood feed, aquatic habitats to lay eggs, and sugar sources for energy. Other states could include a resting period, such as the post-prandial rest to concentrate a blood meal. +``` +library(devtools) +devtools::install_github("dd-harp/ramp.micro") +``` + +After it has been installed, it can be loaded in the normal way: + +``` +library(ramp.micro) +``` + +*** + +![**Figure 1:** In microsimulation models, mosquitoes are in behavioral states (*e.g.* egg laying, *L,* or blood feeding, *F*) and move among points where the required resources are found (*e.g.* aquatic habitats, $\left\{l \right\},$ or blood feeding sites, $\left\{b \right\}$). This diagram was 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]](./vignettes/DynamicsOnPoints.png) + +*** + + +## Microsimulation & Behavioral States + +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 first described for malaria 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]. + +This software also implements several *behavioral state models* for mosquitoes, which are a natural complement to micro-simulation. +The basic premise of is that mosquitoes are in a physiological state that triggers behaviors, including behavioral algorithms to *search* for resources. +The search algorithms have evolved to accomplish tasks, and they may have evolved to increase a mosquito's fitness in context. +To survive and lay eggs, mosquitoes must find resources and accomplish several tasks: find mates; find and blood feed on vertebrate hosts; find aquatic habitats and lay eggs; and find and feed on sugar sources for energy. +Other states could include a resting period, such as the post-prandial rest to concentrate a blood meal. +The mosquito is, meanwhile, responding to avoiding hazards by responding to environmental cues such as wind, temperature, and humidity. + +In these models, Behavioral state models for mosquitoes are a type of compartmental model where mosquito populations are sub-divided by their physiological / behavioral states, and changes in behavioral states can occur as a result of successfully blood feeding, egg laying, sugar feeding, mating, and resting. These behavioral states are different than the Ross-Macdonald model's states that represent infection status for parasite transmission dynamics: uninfected, infected but not yet infective, and infective. By considering *both* the physiological/behavioral state and infection states, it might be possible to understand how local features of malaria transmission could be the result mosquito behavioral ecology and the heterogeneous distribution of resources, an idea pioneered 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]. @@ -18,7 +47,8 @@ called MBITES (Mosquito Bout-based and Individual-based Transmission Ecology Sim was developed by Sean L Wu, *et al.* (2020)^[Wu SL, *et al.*, (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 list of papers is by no means exhaustive, and a systematic review of such models is needed. -*** +## Complexity + These behavioral state models are designed to be highly mimetic. While searching, mosquitoes move around until they find a resource and accomplish the task(s). @@ -40,4 +70,3 @@ The software has a modular design, and there are plans to integrate some of this *** -![**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.](./vignettes/DynamicsOnPoints.png) diff --git a/_pkgdown.yml b/_pkgdown.yml index 404d7ac..2a195cd 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -11,6 +11,10 @@ navbar: href: articles/kernels.html - text: Models href: articles/models.html + - text: Modularity + href: articles/modularity.html + - text: Traps + href: articles/models.html - text: Simulation href: articles/simulation.html - text: Adults @@ -111,11 +115,20 @@ reference: desc: | Plot the single bout dispersal matrices contents: + - plot_Psi_bb + - plot_Psi_bq + - plot_Psi_bs + - plot_Psi_qb + - plot_Psi_qq + - plot_Psi_qs + - plot_Psi_sb + - plot_Psi_sq + - plot_Psi_ss - plot_Psi - plot_Psi.BQ - - plot_Psi_BQ + - plot_Psi_BQmod - plot_Psi.BQS - - plot_Psi_BQS + - plot_Psi_BQSmod - subtitle: Make K desc: | Generate matrices describing feeding or egg laying within a single feeding cycle diff --git a/man/add_points_q.Rd b/man/add_points_q.Rd index 82da3d6..54103a3 100644 --- a/man/add_points_q.Rd +++ b/man/add_points_q.Rd @@ -4,7 +4,7 @@ \alias{add_points_q} \title{Add habitats to a frame} \usage{ -add_points_q(q, wts = 1, pw = 1, max_pt_sz = 1, clr = "#4361eeCC") +add_points_q(q, wts = 1, pw = 1, max_pt_sz = 1, clr = "skyblue") } \arguments{ \item{q}{a point set defining egg laying sites} diff --git a/man/add_points_qq.Rd b/man/add_points_qq.Rd index 2f5afbe..654b3f8 100644 --- a/man/add_points_qq.Rd +++ b/man/add_points_qq.Rd @@ -4,14 +4,7 @@ \alias{add_points_qq} \title{Add habitats with and without the self loop} \usage{ -add_points_qq( - q, - M, - pw = 1, - max_pt_sz = 2, - colA = "#4e148c66", - colB = "#4e148cCC" -) +add_points_qq(q, M, pw = 1, max_pt_sz = 2, colA = "skyblue", colB = "skyblue3") } \arguments{ \item{q}{a point set defining egg laying sites} diff --git a/man/add_points_s.Rd b/man/add_points_s.Rd index af46de1..fcc85b0 100644 --- a/man/add_points_s.Rd +++ b/man/add_points_s.Rd @@ -4,7 +4,7 @@ \alias{add_points_s} \title{Add sugar feeding sites to a frame} \usage{ -add_points_s(s, wts = 1, pw = 1, max_pt_sz = 1, clr = "#ff4800CC") +add_points_s(s, wts = 1, pw = 1, max_pt_sz = 1, clr = "olivedrab2") } \arguments{ \item{s}{a point set defining sugar feeding sites} diff --git a/man/add_points_ss.Rd b/man/add_points_ss.Rd index fe60465..5232846 100644 --- a/man/add_points_ss.Rd +++ b/man/add_points_ss.Rd @@ -9,8 +9,8 @@ add_points_ss( M, pw = 1, max_pt_sz = 2, - colA = "#8bc74266", - colB = "#8bc742CC" + colA = "olivedrab2", + colB = "olivedrab3" ) } \arguments{ diff --git a/man/plot_Psi.BQ.Rd b/man/plot_Psi.BQ.Rd index fc949e4..2117e1b 100644 --- a/man/plot_Psi.BQ.Rd +++ b/man/plot_Psi.BQ.Rd @@ -4,15 +4,6 @@ \alias{plot_Psi.BQ} \title{Visualize the one-bout dispersal matrices for a BQ model} \usage{ -\method{plot_Psi}{BQ}( - model, - max_pt_sz = 2, - min_edge_frac = 0.01, - r = 0.01, - arw_lng = 0.05, - lwd = 2 -) - \method{plot_Psi}{BQ}( model, max_pt_sz = 2, @@ -36,12 +27,8 @@ \item{lwd}{scale the line width} } \value{ -the model, a compound [list] - the model, a compound [list] } \description{ -Visualize the one-bout dispersal matrices for a BQ model - Visualize the one-bout dispersal matrices for a BQ model } diff --git a/man/plot_Psi.BQS.Rd b/man/plot_Psi.BQS.Rd index 773d828..eabb395 100644 --- a/man/plot_Psi.BQS.Rd +++ b/man/plot_Psi.BQS.Rd @@ -4,15 +4,6 @@ \alias{plot_Psi.BQS} \title{Visualize the one-bout dispersal matrices for a BQS model} \usage{ -\method{plot_Psi}{BQS}( - model, - max_pt_sz = 2, - min_edge_frac = 0.01, - r = 0.01, - arw_lng = 0.05, - lwd = 2 -) - \method{plot_Psi}{BQS}( model, max_pt_sz = 2, @@ -36,12 +27,8 @@ \item{lwd}{scale the line width} } \value{ -the model, a compound [list] - the model, a compound [list] } \description{ -Visualize the one-bout dispersal matrices for a BQS model - Visualize the one-bout dispersal matrices for a BQS model } diff --git a/man/plot_Psi.Rd b/man/plot_Psi.Rd index 55fc6db..3042a06 100644 --- a/man/plot_Psi.Rd +++ b/man/plot_Psi.Rd @@ -4,15 +4,6 @@ \alias{plot_Psi} \title{Visualize the one-bout dispersal matrices} \usage{ -plot_Psi( - model, - max_pt_sz = 2, - min_edge_frac = 0.01, - r = 0.01, - arw_lng = 0.05, - lwd = 2 -) - plot_Psi( model, max_pt_sz = 2, @@ -36,12 +27,8 @@ plot_Psi( \item{lwd}{scale the line width} } \value{ -the model, a compound [list] - the model, a compound [list] } \description{ -Visualize the one-bout dispersal matrices - Visualize the one-bout dispersal matrices } diff --git a/man/plot_Psi_BQ.Rd b/man/plot_Psi_BQ.Rd index 3b5656c..d7947d1 100644 --- a/man/plot_Psi_BQ.Rd +++ b/man/plot_Psi_BQ.Rd @@ -1,30 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/Psi_matrices.R -\name{plot_Psi_BQ} -\alias{plot_Psi_BQ} +\name{plot_Psi_bq} +\alias{plot_Psi_bq} \title{Visualize the one-bout dispersal matrices for a BQ model} \usage{ -plot_Psi_BQ( +plot_Psi_bq( b, q, - Psi_bb, - Psi_qb, Psi_bq, - Psi_qq, - max_pt_sz = 2, - min_edge_frac = 0.01, - r = 0.01, - arw_lng = 0.05, - lwd = 2 -) - -plot_Psi_BQ( - b, - q, - Psi_bb, - Psi_qb, - Psi_bq, - Psi_qq, max_pt_sz = 2, min_edge_frac = 0.01, r = 0.01, @@ -37,14 +20,8 @@ plot_Psi_BQ( \item{q}{egg laying sites point set} -\item{Psi_bb}{one bout dispersal matrix from b to b} - -\item{Psi_qb}{one bout dispersal matrix from q to b} - \item{Psi_bq}{one bout dispersal matrix from b to q} -\item{Psi_qq}{one bout dispersal matrix from q to q} - \item{max_pt_sz}{set the maximum cex for points} \item{min_edge_frac}{the fraction of the mass to plot} @@ -56,12 +33,8 @@ plot_Psi_BQ( \item{lwd}{scale the line width} } \value{ -no visible return value - no visible return value } \description{ -Visualize the one-bout dispersal matrices for a BQ model - Visualize the one-bout dispersal matrices for a BQ model } diff --git a/man/plot_Psi_BQS.Rd b/man/plot_Psi_BQSmod.Rd similarity index 79% rename from man/plot_Psi_BQS.Rd rename to man/plot_Psi_BQSmod.Rd index 34c2f55..c3938a1 100644 --- a/man/plot_Psi_BQS.Rd +++ b/man/plot_Psi_BQSmod.Rd @@ -1,30 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/Psi_matrices.R -\name{plot_Psi_BQS} -\alias{plot_Psi_BQS} +\name{plot_Psi_BQSmod} +\alias{plot_Psi_BQSmod} \title{Visualize the one-bout dispersal matrices for a BQS model} \usage{ -plot_Psi_BQS( - b, - q, - s, - Psi_bb, - Psi_qb, - Psi_sb, - Psi_bq, - Psi_qq, - Psi_sq, - Psi_bs, - Psi_qs, - Psi_ss, - max_pt_sz = 2, - min_edge_frac = 0.01, - r = 0.01, - arw_lng = 0.05, - lwd = 2 -) - -plot_Psi_BQS( +plot_Psi_BQSmod( b, q, s, @@ -80,12 +60,8 @@ plot_Psi_BQS( \item{lwd}{scale the line width} } \value{ -no visible return value - no visible return value } \description{ -Visualize the one-bout dispersal matrices for a BQS model - Visualize the one-bout dispersal matrices for a BQS model } diff --git a/man/plot_Psi_BQmod.Rd b/man/plot_Psi_BQmod.Rd new file mode 100644 index 0000000..cd6cd41 --- /dev/null +++ b/man/plot_Psi_BQmod.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_BQmod} +\alias{plot_Psi_BQmod} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_BQmod( + b, + q, + Psi_bb, + Psi_qb, + Psi_bq, + Psi_qq, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{Psi_bb}{one bout dispersal matrix from b to b} + +\item{Psi_qb}{one bout dispersal matrix from q to b} + +\item{Psi_bq}{one bout dispersal matrix from b to q} + +\item{Psi_qq}{one bout dispersal matrix from q to q} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_bb.Rd b/man/plot_Psi_bb.Rd new file mode 100644 index 0000000..d038444 --- /dev/null +++ b/man/plot_Psi_bb.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_bb} +\alias{plot_Psi_bb} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_bb( + b, + q, + Psi_bb, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{Psi_bb}{one bout dispersal matrix from b to b} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_bs.Rd b/man/plot_Psi_bs.Rd new file mode 100644 index 0000000..fca9c7b --- /dev/null +++ b/man/plot_Psi_bs.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_bs} +\alias{plot_Psi_bs} +\title{Visualize the dispersal matrix to b from s} +\usage{ +plot_Psi_bs( + b, + q, + s, + Psi_bs, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{s}{sugar feeding sites point set} + +\item{Psi_bs}{one bout dispersal matrix to b from s} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the dispersal matrix to b from s +} diff --git a/man/plot_Psi_qb.Rd b/man/plot_Psi_qb.Rd new file mode 100644 index 0000000..b74b317 --- /dev/null +++ b/man/plot_Psi_qb.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_qb} +\alias{plot_Psi_qb} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_qb( + b, + q, + Psi_qb, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{Psi_qb}{one bout dispersal matrix from q to b} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_qq.Rd b/man/plot_Psi_qq.Rd new file mode 100644 index 0000000..2a5a1b7 --- /dev/null +++ b/man/plot_Psi_qq.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_qq} +\alias{plot_Psi_qq} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_qq( + b, + q, + Psi_qq, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{Psi_qq}{one bout dispersal matrix from q to q} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_qs.Rd b/man/plot_Psi_qs.Rd new file mode 100644 index 0000000..3a53261 --- /dev/null +++ b/man/plot_Psi_qs.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_qs} +\alias{plot_Psi_qs} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_qs( + b, + q, + s, + Psi_qs, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{s}{sugar feeding sites point set} + +\item{Psi_qs}{one bout dispersal matrix to q from s} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_sb.Rd b/man/plot_Psi_sb.Rd new file mode 100644 index 0000000..9774049 --- /dev/null +++ b/man/plot_Psi_sb.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_sb} +\alias{plot_Psi_sb} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_sb( + b, + q, + s, + Psi_sb, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{s}{sugar feeding sites point set} + +\item{Psi_sb}{one bout dispersal matrix to s from b} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_sq.Rd b/man/plot_Psi_sq.Rd new file mode 100644 index 0000000..427be8b --- /dev/null +++ b/man/plot_Psi_sq.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_sq} +\alias{plot_Psi_sq} +\title{Visualize the one-bout dispersal matrices for a BQ model} +\usage{ +plot_Psi_sq( + b, + q, + s, + Psi_sq, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{s}{sugar feeding sites point set} + +\item{Psi_sq}{one bout dispersal matrix to s from q} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a BQ model +} diff --git a/man/plot_Psi_ss.Rd b/man/plot_Psi_ss.Rd new file mode 100644 index 0000000..7707e21 --- /dev/null +++ b/man/plot_Psi_ss.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Psi_matrices.R +\name{plot_Psi_ss} +\alias{plot_Psi_ss} +\title{Visualize the one-bout dispersal matrices for a Bs model} +\usage{ +plot_Psi_ss( + b, + q, + s, + Psi_ss, + max_pt_sz = 2, + min_edge_frac = 0.01, + r = 0.01, + arw_lng = 0.05, + lwd = 2 +) +} +\arguments{ +\item{b}{blood feeding sites point set} + +\item{q}{egg laying sites point set} + +\item{s}{sugar feeding sites point set} + +\item{Psi_ss}{one bout dispersal matrix from s to s} + +\item{max_pt_sz}{set the maximum cex for points} + +\item{min_edge_frac}{the fraction of the mass to plot} + +\item{r}{the radius of a ring around destination points} + +\item{arw_lng}{the arrow length} + +\item{lwd}{scale the line width} +} +\value{ +no visible return value +} +\description{ +Visualize the one-bout dispersal matrices for a Bs model +} diff --git a/vignettes/dispersal.Rmd b/vignettes/dispersal.Rmd index 65869b0..dca4f31 100644 --- a/vignettes/dispersal.Rmd +++ b/vignettes/dispersal.Rmd @@ -7,3 +7,81 @@ vignette: > %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- + +This has been adapted from the manuscript **Mosquito Dispersal in Context,** currently in draft form. + +## Flight Bout + +In a single flight bout, mosquito dispersal in a model is defined by point sets and dispersal kernels (*i.e.*, $\Psi$). For mosquito populations, dispersal can be understood through these population dynamic models, where we are interested in describing movement to complete a phase of the feeding cycle, or through one complete feeding cycle. + + +## Movement Through a Behavioral State + +Movement to accomplish a tasks could involve a sequence of search bouts, some of which may be unsuccessful. A functionally relevant measure of dispersal tracks movement: starting after laying eggs through failures until a surviving mosquito successfully blood feeds; or starting after blood feeding through failures until a mosquito successfully lays eggs. + +**Kxy** + +Since there could be several failures, we modified the population dynamic models, creating a ``trap'' algorithm to compute progress through a part of the feeding cycle. To do so, we modify the simulation by setting parameters to zero that determine the fraction of mosquitoes that would otherwise leave the state. We then initialize and follow a cohort, iterating until almost surviving mosquitoes are trapped in the end state (*i.e.*, up to a predefined tolerance). We let $K_{b\leftarrow q}$ denote a $|b| \times |q|$ matrix describing net dispersal to blood feed once: it is the proportion of mosquitoes leaving $\left\{q\right\}$ after laying eggs that eventually blood feed successfully at each point in $\left\{b\right\}$. Similarly, we define $K_{q \leftarrow b}$ denote net dispersal to lay eggs after. + +The matrices generated by the trap variable algorithm describe movement through blood feeding and egg laying, even in models with sugar feeding. With sugar feeding, a mosquito that has laid eggs \textit{must} blood feed before laying again. A mosquito may fail to lay eggs and switch to sugar feeding, and then blood feed again before successfully laying eggs (Fig~\ref{sugarDiagram}). We can compute the matrices $K_{b\leftarrow q}$ and $K_{q \leftarrow b}$ accounting for the fact that a mosquito may sugar feed -- possibly multiple times -- before ending in the other state. Under the assumptions of this model, there may be some gonotrophic disassociation; a mosquito will always blood feed after sugar feeding, even if it was searching for aquatic habitat before the transition (Fig.~\ref{sugarDiagram}). In such cases, $K_{b\leftarrow b}$ is the interval between blood meals with or without an egg batch, but because of the delay for parasite development, we must take even greater care in quantifying parasite dispersal by mosquitoes (see below). + + +## Movement Through the Feeding Cycle + + +The matrices $K_{bq}$ and $K_{qb}$ define a new, bipartite graph that describes movement among the point sets where mosquitoes lay eggs and where they blood feed (Fig~\ref{Kxx}). In block form, movement through egg-laying and (possibly) sugar feeding can be represented in block form: +% +\begin{equation} K = \left[ \begin{array}{cc} + 0 & K_{b \leftarrow q} \\ + K_{q \leftarrow b} & 0 +\end{array} \right] +\label{KbqKqb} +\end{equation} + +After blood feeding and egg laying once -- one complete feeding cycle -- the bipartite graph disconnects into two complementary graphs on their respective point sets: + +\begin{equation} K^2 = \left[\begin{array}{cc} + K_{b \leftarrow b}& 0 \\ + 0 & K_{q \leftarrow q} +\end{array} \right] +\label{KbbKqq} +\end{equation} + +The matrix $K_{b \leftarrow b} = K_{b \leftarrow q}\cdot K_{q \leftarrow b} $ describes movement from haunts to haunts, and $K_{q \leftarrow q}= K_{q \leftarrow b}\cdot K_{b \leftarrow q}$ describes movement from habitats to habitats. + +**Kxx** + +## Egg Laying + +We developed algorithms to compute net dispersal of eggs away from a natal site. Net lifetime dispersal of eggs from natal aquatic habitats is summed over all gonotrophic cycles, $i$, until a mosquito has died. The expected number of eggs laid per emerging adult female at each site can be computed as: +% +\begin{equation} + G = o \sum_{i=1}^\infty \left(K_{q\leftarrow q}\right)^i. +\end{equation} +% +The quantity $G$ is mosquito lifetime egg dispersal kernel for a cohort. We also define net egg dispersal by the population at its steady state +% +\begin{equation} +G \cdot \mbox{diag}\left(\bar Q \right), +\end{equation} +% +where $\bar Q$ is the steady state density of adult female mosquitoes at $\left\{q\right\}$. + + +## Pathogen Dispersal + +We developed algorithms to compute potential dispersal of pathogens from the points where mosquitoes blood feeds. A basic formula for the dispersion of infective bites away from an infectious host must consider the delay for the extrinsic incubation period. Since chronological and reproductive age are not necessarily in sync, and since there might be gonotrophic disassociation, we can't use $K_{b\rightarrow b}$. Instead, we simply run the simulation, summing up all potential transmission events, just as we would compute vectorial capacity. + +Net dispersal of pathogens is computed by setting an initial cohort of mosquitoes that successfully took a blood meal, $B_0$, among haunts and iterating the model until all of the mosquitoes are dead. The number of infective bites given by the cohort is found by adding up all the bites after $\tau$ days, where $\tau$ is a parameter describing the EIP. Given $B_0$, we use the model to compute $B_t$ for a cohort of mosquitoes, and we define $V$ as +% +\begin{equation} +V = \sum_{t=\tau}^\infty \mbox{diag} \left(\psi B_t \right). +\end{equation} +% +While $V$ defines parasite dispersal by a cohort of mosquitoes, weighted evenly by point, we can also weight parasite dispersal by the steady state population density at each point, which we call potential pathogen dispersion, $P = V \cdot \mbox{diag}\left(\bar B \right)$, where $\bar B$ is the steady state density of adult female mosquitoes at $\left\{b\right\}$. + +The matrix $P$ defines a quantity that differs slightly from the definition of vectorial capacity, in that it is not the expected number of bites arising from all the mosquitoes blood feeding on a single person. Instead, it is the expected number of infective bites arising from all the mosquitoes blood feeding at a single haunt on a single day, computed as if every available host was perfectly infectious. The quantity would be identical to \textit{vectorial capacity} if it were normalized by the number of hosts available (\textit{i.e.} modifying $B_0$), such that the quantity was an expected number arising from a single host. + +## Dispersal Distances + +Any pair of matrices describing dispersal propensities among points in a set and the distances among points in that set can be normalized to define a probability distribution function. Since the number of destinations is finite, dispersal is described using probability mass functions (PMFs). diff --git a/vignettes/kernels.R b/vignettes/kernels.R index 19b2c5e..726e5b1 100644 --- a/vignettes/kernels.R +++ b/vignettes/kernels.R @@ -3,15 +3,58 @@ library(ramp.micro) ## ----------------------------------------------------------------------------- set.seed(24328) -bb = unif_xy(256, -17, 17) -qq = unif_xy(289, -17, 17) +bb = unif_xy(96, -17, 17) +qq = unif_xy(89, -17, 17) +ss = unif_xy(72, -17, 17) ## ----------------------------------------------------------------------------- kFb = make_kF_exp(k=2, s=1, gamma=1.5) kFq = make_kF_exp(k=2, s=2, gamma=2) +kFs = make_kF_exp(k=3, s=2, gamma=2) ## ----fig.height=4, fig.width=6------------------------------------------------ dd = seq(0, 5, by = 0.01) plot(dd, kFb(dd), type = "l", col = "darkred", xlab = "Distance", ylab = "Weight") lines(dd, kFq(dd), type = "l", col = "darkblue") +lines(dd, kFs(dd), type = "l", col = "olivedrab4") + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_bq = make_Psi_xy(qq, bb, kFb, w=1) +plot_Psi_bq(bb, qq, Psi_bq) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_bb = make_Psi_xx(bb, kFb, w=1, stay=0.5) +plot_Psi_bb(bb, qq, Psi_bb) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_bs = make_Psi_xy(ss, bb, kFb, w=1) +plot_Psi_bs(bb, qq, ss, Psi_bs) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_qb = make_Psi_xy(bb, qq, kFb, w=1) +plot_Psi_qb(bb, qq, Psi_qb) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_qq = make_Psi_xx(qq, kFq, w=1, stay=0.3) +plot_Psi_qq(bb, qq, Psi_qq) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_sb = make_Psi_xy(bb, ss, kFs, w=1) +plot_Psi_sb(bb, qq, ss, Psi_sb) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_sq = make_Psi_xy(qq, ss, kFs, w=1) +plot_Psi_sq(bb, qq, ss, Psi_sq) + +## ----fig.height=7, fig.width=7------------------------------------------------ +par(mar = c(1,1,2,2)) +Psi_ss = make_Psi_xx(ss, kFs, w=1, stay=0.05) +plot_Psi_ss(bb, qq, ss, Psi_ss) diff --git a/vignettes/kernels.Rmd b/vignettes/kernels.Rmd index 265d5b8..f9845b7 100644 --- a/vignettes/kernels.Rmd +++ b/vignettes/kernels.Rmd @@ -16,15 +16,27 @@ library(ramp.micro) ```{r} set.seed(24328) -bb = unif_xy(256, -17, 17) -qq = unif_xy(289, -17, 17) +bb = unif_xy(96, -17, 17) +qq = unif_xy(89, -17, 17) +ss = unif_xy(72, -17, 17) ``` -### Dispersal +## Kernel Shapes + +We use functions to generate the probability of finding a point as a function of its distance and context. Let $d_{i,j}$ denote the distance from point $i$ to $j$. A scalar $\omega_j$ is a linear weight on each destination making it more or less attractive from every distance. + +We define some function, $F_w$ that assigns a weight to every potential destination by distance. These weights are used to compute dispersal matrices (see below). + +### Exponential + +\begin{equation} +w_{j\rightarrow i} = F_w (d_{i,j}) = \omega_j \left(e^{-k \left( \frac{d_{i,j}}{s}\right)^\gamma} \right). +\end{equation} ```{r} kFb = make_kF_exp(k=2, s=1, gamma=1.5) kFq = make_kF_exp(k=2, s=2, gamma=2) +kFs = make_kF_exp(k=3, s=2, gamma=2) ``` @@ -32,4 +44,98 @@ kFq = make_kF_exp(k=2, s=2, gamma=2) dd = seq(0, 5, by = 0.01) plot(dd, kFb(dd), type = "l", col = "darkred", xlab = "Distance", ylab = "Weight") lines(dd, kFq(dd), type = "l", col = "darkblue") +lines(dd, kFs(dd), type = "l", col = "olivedrab4") +``` + +### Power Law + +\begin{equation} +w_{j\rightarrow i} = F_w (d_{i,j}) = \omega_j \left(\frac{\epsilon}{s+d_{i,j}} \right). +\end{equation} + +### Mixture + +The next function the sum of the two previous functions, where $\epsilon$ is the *weight* on each one of the functions. + +\begin{equation} +w_{j\rightarrow i} = F_w (d_{i,j}) = \omega_j \left((1-\epsilon) e^{-k \left( \frac{d_{i,j}}{s}\right)^\gamma} + \frac{\epsilon}{s+d_{i,j}} \right). +\end{equation} + +## Dispersal Matrices + +Movement among point sets is modeled using matrices that describe where mosquitoes end up after dispersing in a single time step. The proportion moving from a point in one set to another, from $x\in \left\{ x \right\}$ to $y \in \left\{ y \right\}$, is described by a matrix $\Psi_{y\leftarrow x}$ or equivalently $\Psi_{yx}$. Similarly, the proportion moving from a point in one set to a point in the other is $\Psi_{xx}$. + +In translating distances into a probability mass function using the kernel shapes, we let + +$$w_{i,j} = F_w(d_{i,j})$$ +These weights are normalized and translated into proportions: the proportion arriving at each point in a destination set index by $j$ from a source set indexed by $i$ is normalized across all destinations from each starting point: + +\begin{equation} +\Psi_{j,i} \in \Psi = \frac{w_{i,j}} {\sum_i w_{i,j}} +\end{equation} + +Note that in the simulation models, these matrices describe the destinations for surviving mosquitoes, so we constrain the formulas such that each column sums to one. Mortality associated with dispersing is associated with the source points. + + +### Blood Feeding + +After emerging or after blood feeding, mosquitoes move from aquatic habitats to blood feed. + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_bq = make_Psi_xy(qq, bb, kFb, w=1) +plot_Psi_bq(bb, qq, Psi_bq) +``` + +If they are unsuccessful, they will try to blood feed again. In the visualization, asymmetries arise because of the distribution of other points: $a$ and $b$ are close, and both are further away from $c$ so mosquitoes will tend to go back and forth between $a$ and $b$ and away from $c.$ The asymmetry is plotted by letting the colored portion of the arrow *start* + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_bb = make_Psi_xx(bb, kFb, w=1, stay=0.5) +plot_Psi_bb(bb, qq, Psi_bb) +``` + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_bs = make_Psi_xy(ss, bb, kFb, w=1) +plot_Psi_bs(bb, qq, ss, Psi_bs) +``` + +### Egg Laying + +After blood feeding, mosquitoes move from blood feeding sites to aquatic habitats. + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_qb = make_Psi_xy(bb, qq, kFb, w=1) +plot_Psi_qb(bb, qq, Psi_qb) +``` + + +If they fail, mosquitoes will move again. + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_qq = make_Psi_xx(qq, kFq, w=1, stay=0.3) +plot_Psi_qq(bb, qq, Psi_qq) +``` + +### Sugar Feeding + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_sb = make_Psi_xy(bb, ss, kFs, w=1) +plot_Psi_sb(bb, qq, ss, Psi_sb) +``` + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_sq = make_Psi_xy(qq, ss, kFs, w=1) +plot_Psi_sq(bb, qq, ss, Psi_sq) +``` + +```{r, fig.height=7, fig.width=7} +par(mar = c(1,1,2,2)) +Psi_ss = make_Psi_xx(ss, kFs, w=1, stay=0.05) +plot_Psi_ss(bb, qq, ss, Psi_ss) ``` diff --git a/vignettes/models.R b/vignettes/models.R new file mode 100644 index 0000000..d14b407 --- /dev/null +++ b/vignettes/models.R @@ -0,0 +1,25 @@ +## ----------------------------------------------------------------------------- +library(ramp.micro) + +## ----------------------------------------------------------------------------- +set.seed(24328) +bb = unif_xy(256, -17, 17) +qq = unif_xy(289, -17, 17) +ss = unif_xy(225, -17, 17) + +## ----------------------------------------------------------------------------- +kFb = make_kF_exp(k=2, s=1, gamma=1.5) +kFq = make_kF_exp(k=2, s=2, gamma=2) +kFs = make_kF_exp(k=3, s=2, gamma=2) + +## ----------------------------------------------------------------------------- +opts_d = list(kFb = kFb, kFq = kFq) +model = setup_model(bb, qq, dispersal_opts=opts_d) + +## ----------------------------------------------------------------------------- +names(model) + +## ----------------------------------------------------------------------------- +opts_d = list(kFb = kFb, kFq = kFq, kFs=kFs) +model = setup_model(bb, qq, ss, dispersal_opts=opts_d) + diff --git a/vignettes/models.Rmd b/vignettes/models.Rmd index 538bf70..c9646ea 100644 --- a/vignettes/models.Rmd +++ b/vignettes/models.Rmd @@ -7,3 +7,44 @@ vignette: > %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- + +```{r} +library(ramp.micro) +``` + +## Define Point Sets + +```{r} +set.seed(24328) +bb = unif_xy(256, -17, 17) +qq = unif_xy(289, -17, 17) +ss = unif_xy(225, -17, 17) +``` + + +## Define Kernel Shapes + +```{r} +kFb = make_kF_exp(k=2, s=1, gamma=1.5) +kFq = make_kF_exp(k=2, s=2, gamma=2) +kFs = make_kF_exp(k=3, s=2, gamma=2) +``` + +## Setup BQ + +```{r} +opts_d = list(kFb = kFb, kFq = kFq) +model = setup_model(bb, qq, dispersal_opts=opts_d) +``` + +```{r} +names(model) +``` + + +## Setup BQS + +```{r} +opts_d = list(kFb = kFb, kFq = kFq, kFs=kFs) +model = setup_model(bb, qq, ss, dispersal_opts=opts_d) +``` diff --git a/vignettes/modularity.Rmd b/vignettes/modularity.Rmd index 2cd2272..de85ebb 100644 --- a/vignettes/modularity.Rmd +++ b/vignettes/modularity.Rmd @@ -11,8 +11,49 @@ vignette: > library(ramp.micro) ``` -This software has a modular design with two components. +This software has a modular design with two components. Modularity in the design is implemented using one of R's basic basic object oriented methods, the `S3 Class.` -+ The **M** component describes adult mosquitoes +In a nutshell, there are two dynamical components: -+ The **L** component describes aquatic mosquitoes ++ The **M** component describes adult mosquito population dynamics + ++ The **L** component describes aquatic mosquito population dynamics + +To develop a modular simulation framework, each dynamical component defines a common set of functions that are called. Each module in the class defines its own `S3` method. + +## **M** Component + +### Methods + ++ `setup_adult_model` + + + `make_Psi_*` + + + `setup_dispersal_*` + + + `setup_bionomics_*` + + + `make_demography_*` + ++ `save_states_M` + ++ `compute_diffs_M` + ++ `init_states_M` + ++ `init_adult_model` is a wrapper that calls `init_adult_model_*` + + + + +### Modules + +There are currently two + +## **L** Component + +### Setup + +### Methods + +### Modules diff --git a/vignettes/point_sets.R b/vignettes/point_sets.R index c5b7866..3b50b51 100644 --- a/vignettes/point_sets.R +++ b/vignettes/point_sets.R @@ -2,18 +2,24 @@ library(ramp.micro) ## ----------------------------------------------------------------------------- -p1 <- unif_xy(150, -10, 10) -head(p1, 4) +x= c(1,0,1,0) +y= c(0,1,1,0) +xy0 <- cbind(x,y) +xy0 ## ----------------------------------------------------------------------------- -dim(p1) +xy1 <- unif_xy(50, 0, 10) +head(xy1, 4) + +## ----------------------------------------------------------------------------- +dim(xy1) ## ----fig.height=5, fig.width=5------------------------------------------------ par(mar = c(2,2,1,1), bty = "o") -plot(p1) +plot(xy1) ## ----fig.height=5, fig.width=5------------------------------------------------ -p2 <- lattice(17, -8, 8) +p2 <- lattice(7, 0, 10) par(mar = c(2,2,1,1), bty = "o") plot(p2) @@ -21,7 +27,7 @@ plot(p2) dim(p2) ## ----------------------------------------------------------------------------- -seeds <- unif_xy(23, -20, 20) +seeds <- unif_xy(23, 0, 50) p3 <- clusters_xy(seeds, 8, 1) ## ----fig.height=5, fig.width=5------------------------------------------------ diff --git a/vignettes/point_sets.Rmd b/vignettes/point_sets.Rmd index a79032d..0c62c45 100644 --- a/vignettes/point_sets.Rmd +++ b/vignettes/point_sets.Rmd @@ -13,31 +13,44 @@ library(ramp.micro) ## Introduction -In `ramp.micro`, resource point sets are stored in two columns, and there are utilities for creating point sets for toy models. This is a quick guide. +Models in `ramp.micro` are developed around point sets describing the locations of resources. Point sets are passed to functions that set up models. For these purposes, the point sets are stored in two columns as a pair of named vectors. + +For example: + +```{r} +x= c(1,0,1,0) +y= c(0,1,1,0) +xy0 <- cbind(x,y) +xy0 +``` + +Note that the points are returned as a pair of named vectors -- the first column is named `x` and the next one `y` + +To develop code and facilitate methods development, we developed several utilities for creating point sets. ## Uniform -`unif_xy(n, mn, mx)` generates random uniform point sets on a box: +The function `unif_xy(n, mn, mx)` generates random uniform point sets within a square bounding box: + `mn` $< x <$ `mx` + `mn` $< y <$ `mx` -The points are returned as a pair of named vectors -- the first column is named `x` and the next one `y` +This creates a set of 150 points that are uniformly, randomly distributed in a 10 unit box: ```{r} -p1 <- unif_xy(150, -10, 10) -head(p1, 4) +xy1 <- unif_xy(50, 0, 10) +head(xy1, 4) ``` -Note that `p1` is $150 \times 2$ +Note that `xy1` is $150 \times 2$ ```{r} -dim(p1) +dim(xy1) ``` ```{r, fig.height=5, fig.width=5} par(mar = c(2,2,1,1), bty = "o") -plot(p1) +plot(xy1) ``` ## Lattice @@ -49,7 +62,7 @@ The function `lattice(n, mn, mx)` generates an $n \times n$ lattice inside a box + `mn` $< y <$ `mx` ```{r, fig.height=5, fig.width=5} -p2 <- lattice(17, -8, 8) +p2 <- lattice(7, 0, 10) par(mar = c(2,2,1,1), bty = "o") plot(p2) ``` @@ -63,7 +76,7 @@ dim(p2) Two functions were developed to generate clusters. The first one, `clusters_xy(xy, nc, vr)` generates a poisson number of points (mean = `nc`) around a set of seeds. The distance from the center of each seed is a normal variate with variance `vr.` ```{r} -seeds <- unif_xy(23, -20, 20) +seeds <- unif_xy(23, 0, 50) p3 <- clusters_xy(seeds, 8, 1) ``` diff --git a/vignettes/simulation.R b/vignettes/simulation.R index efc991f..905909e 100644 --- a/vignettes/simulation.R +++ b/vignettes/simulation.R @@ -31,7 +31,7 @@ Psi_qq = make_Psi_xx(qq, kFq) ## ----fig.height=8, fig.width=8------------------------------------------------ par(mfcol = c(2,2), mar = c(1,2,1,2)) -plot_Psi_BQ(bb, qq, Psi_bb, Psi_qb, Psi_bq, Psi_qq) +plot_Psi_BQmod(bb, qq, Psi_bb, Psi_qb, Psi_bq, Psi_qq) ## ----------------------------------------------------------------------------- opts_d = list(kFb = kFb, kFq = kFq) @@ -49,9 +49,6 @@ names(model$Lpar) ## ----------------------------------------------------------------------------- model <- SIM(model) -## ----eval=F, echo=F----------------------------------------------------------- -# devtools::load_all() - ## ----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) diff --git a/vignettes/simulation.Rmd b/vignettes/simulation.Rmd index 4dd2f39..068d6ad 100644 --- a/vignettes/simulation.Rmd +++ b/vignettes/simulation.Rmd @@ -67,7 +67,7 @@ Psi_qq = make_Psi_xx(qq, kFq) ```{r, fig.height=8, fig.width=8} par(mfcol = c(2,2), mar = c(1,2,1,2)) -plot_Psi_BQ(bb, qq, Psi_bb, Psi_qb, Psi_bq, Psi_qq) +plot_Psi_BQmod(bb, qq, Psi_bb, Psi_qb, Psi_bq, Psi_qq) ``` @@ -102,9 +102,6 @@ We can solve the model and produce output by calling the function `SIM` 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. Here, the size of each point scales with the density of the adult, female mosquito population at that point (red = blood feeding, blue = egg laying).