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

Dev #146

Merged
merged 2 commits into from
Dec 14, 2023
Merged

Dev #146

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ inst/doc
CRAN-SUBMISSION
cran-comments.md
docs
.Rproj.user
.Rdata
.quarto
18 changes: 18 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ S3method(update_inits_X,SIP)
S3method(update_inits_X,SIS)
S3method(update_inits_X,hMoI)
S3method(update_inits_X,trace)
S3method(xde_lines_X,SIP)
S3method(xde_lines_X,SIS)
S3method(xde_plot_X,SIP)
S3method(xde_plot_X,SIS)
S3method(xde_solve,aqua)
S3method(xde_solve,aqua_dde)
S3method(xde_solve,cohort)
Expand Down Expand Up @@ -458,6 +462,20 @@ export(xDE_diffeqn_aquatic)
export(xDE_diffeqn_cohort)
export(xDE_diffeqn_human)
export(xDE_diffeqn_mosy)
export(xde_lines_EIR)
export(xde_lines_M)
export(xde_lines_PR)
export(xde_lines_X)
export(xde_lines_YZ)
export(xde_lines_YZ_fracs)
export(xde_lines_aEIR)
export(xde_plot_EIR)
export(xde_plot_M)
export(xde_plot_PR)
export(xde_plot_X)
export(xde_plot_YZ)
export(xde_plot_YZ_fracs)
export(xde_plot_aEIR)
export(xde_setup)
export(xde_setup_aquatic)
export(xde_setup_cohort)
Expand Down
6 changes: 5 additions & 1 deletion R/adult-RM.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,12 @@ get_inits_MYZ.RM_ode <- function(pars) {with(pars$MYZinits,{
#' @title Return initial values as a vector
#' @description Implements [get_inits_MYZ] for the RM model.
#' @inheritParams get_inits_MYZ
#' @return none
#' @return [numeric]
#' @export
get_inits_MYZ.RM_dde <- function(pars) {with(pars$MYZinits,{
c(M0, P0, Y0, Z0, as.vector(Upsilon0), rep(0, 3*pars$nPatches))
})}




2 changes: 1 addition & 1 deletion R/adult-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ parse_deout_MYZ <- function(deout, pars) {
UseMethod("parse_deout_MYZ", pars$MYZpar)
}


#' @title Return initial values as a vector
#' @description This method dispatches on the type of `pars$MYZpar`.
#' @param pars a [list]
Expand Down Expand Up @@ -151,4 +152,3 @@ update_inits_MYZ <- function(pars, y0) {
make_Omega <- function(g, sigma, K, nPatches) {
diag(g, nPatches) + ((diag(nPatches) - K) %*% diag(sigma, nPatches))
}

39 changes: 39 additions & 0 deletions R/human-SIP.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,42 @@ update_inits_X.SIP <- function(pars, y0) {
get_inits_X.SIP <- function(pars){with(pars$Xinits,{
c(X0, P0)
})}


#' Plot the density of infected individuals for the SIP model
#'
#' @inheritParams xde_plot_X
#' @export
xde_plot_X.SIP = function(pars, clrs=c("black", "darkgreen"), llty=1, stable=FALSE, add_axes=TRUE){
vars=with(pars$outputs,if(stable==TRUE){stable_orbits}else{orbits})

if(add_axes==TRUE)
with(vars$XH,
plot(time, 0*time, type = "n", ylim = c(0, max(H)),
ylab = "# Infected", xlab = "Time"))

xde_lines_X(vars$XH, pars, clrs, llty)
}


#' Add lines for the density of infected individuals for the SIP model
#'
#' @inheritParams xde_lines_X
#'
#' @export
xde_lines_X.SIP = function(XH, pars, clrs=c("black", "darkgreen"), llty=1){
with(XH,{
if(pars$nStrata==1) {
lines(time, X, col=clrs[1], lty = llty[1])
lines(time, P, col=clrs[2], lty = llty[1])
}
if(pars$nStrata>1){
if (length(clrs)==1) clrs=matrix(clrs, 2, pars$nStrata)
if (length(llty)==1) llty=rep(llty, pars$nStrata)
for(i in 1:pars$nStrata){
lines(time, X[,i], col=clrs[1,i], lty = llty[i])
lines(time, P[,i], col=clrs[2,i], lty = llty[i])
}
}
})}

33 changes: 33 additions & 0 deletions R/human-SIS.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,36 @@ update_inits_X.SIS <- function(pars, y0) {
get_inits_X.SIS <- function(pars){
pars$Xinits$X0
}

#' Plot the density of infected individuals for the SIS model
#'
#' @inheritParams xde_plot_X
#' @export
xde_plot_X.SIS = function(pars, clrs="black", llty=1, stable=FALSE, add_axes=TRUE){
vars=with(pars$outputs,if(stable==TRUE){stable_orbits}else{orbits})

if(add_axes==TRUE)
with(vars$XH,
plot(time, 0*time, type = "n", ylim = c(0, max(H)),
ylab = "# Infected", xlab = "Time"))

xde_lines_X(vars$XH, pars, clrs, llty)
}


#' Add lines for the density of infected individuals for the SIS model
#'
#' @inheritParams xde_lines_X
#'
#' @export
xde_lines_X.SIS = function(XH, pars, clrs="black", llty=1){
with(XH,{
if(pars$nStrata==1) lines(time, X, col=clrs[1], lty = llty[1])
if(model$nStrata>1){
if (length(clrs)==1) clrs=rep(clrs, model$nStrata)
if (length(llty)==1) llty=rep(llty, model$nStrata)
for(i in 1:model$nStrata){
lines(time, X[,i], col=clrs[i], lty = llty[i])
}
}
})}
25 changes: 25 additions & 0 deletions R/human-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,28 @@ HTC <- function(pars) {
UseMethod("get_inits_X", pars$Xpar)
}

#' Basic plotting for epidemiological models
#'
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param clrs a [character] vector of colors
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#' @param stable a [logical] set to FALSE for `orbits` and TRUE for `stable_orbits`
#' @param add_axes a [logical] to plot axes only if TRUE
#'
#' @export
xde_plot_X = function(pars, clrs="black", llty=1, stable=FALSE, add_axes=TRUE){
UseMethod("xde_plot_X", pars$Xpar)
}

#' Add lines for basic outputs of epidemiological models
#'
#' @param XH a [list] with the outputs of `exDE::parse_deout()`
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param clrs a [character] vector of colors
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#'
#' @export
xde_lines_X = function(XH, pars, clrs="black", llty=1){
UseMethod("xde_lines_X", pars$Xpar)
}

135 changes: 135 additions & 0 deletions R/plot-MYZ.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@

#' Plot adult mosquito population density
#'
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param clrs a [character] vector of colors
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#' @param stable a [logical] set to FALSE for `orbits` and TRUE for `stable_orbits`
#' @param add_axes a [logical] to plot axes only if TRUE
#'
#' @export
xde_plot_M = function(pars, clrs="darkblue", llty=1, stable=FALSE, add_axes=TRUE){
vars=with(pars$outputs,if(stable==TRUE){stable_orbits}else{orbits})

if(add_axes == TRUE) with(vars$MYZ,
plot(time, 0*time, type = "n", ylim = range(0,max(M)),
ylab = "Mosquito Density", xlab = "Time"))

xde_lines_M(vars$MYZ, pars, clrs, llty)
}

#' Add lines for adult mosquito population density
#'
#' @param MYZ a [list] the output of `exDE::parse_deout()`
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param clrs a [character] vector of colors
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#'
#' @export
xde_lines_M = function(MYZ, pars, clrs="darkblue", llty=1){
with(MYZ,{
if(pars$nPatches==1) lines(time, M, col=clrs[1], lty = llty[1])
if(pars$nPatches>1){
if (length(clrs)==1) clrs=rep(clrs, pars$nPatches)
if (length(llty)==1) llty=rep(llty, pars$nPatches)
for(i in 1:pars$nPatches){
lines(time, M[,i], col=clrs[i], lty = llty[i])
}
}
})}

#' Plot the density of infected and infective mosquitoes
#'
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param Yclrs a [character] vector of colors for infected mosquitoes
#' @param Zclrs a [character] vector of colors for infective mosquitoes
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#' @param stable a [logical] set to FALSE for `orbits` and TRUE for `stable_orbits`
#' @param add_axes a [logical] to plot axes only if TRUE
#'
#' @export
xde_plot_YZ = function(pars, Yclrs = "purple", Zclrs="darkred", llty=1, stable=FALSE, add_axes=TRUE){
vars=with(pars$outputs,if(stable==TRUE){stable_orbits}else{orbits})

if(add_axes == TRUE)
with(vars$MYZ,
plot(time, 0*time, type = "n", ylim = range(0,max(Y)),
ylab = "Mosquito Density", xlab = "Time"))

xde_lines_YZ(vars$MYZ, pars, Yclrs, Zclrs, llty)
}

#' Add lines for the density of infected and infective mosquitoes
#'
#' @param MYZ a [list] the output of `exDE::parse_deout()`
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param Yclrs a [character] vector of colors
#' @param Zclrs a [character] vector of colors
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#'
#' @export
xde_lines_YZ = function(MYZ, pars, Yclrs="purple", Zclrs = "darkred", llty=1){
with(MYZ,{
if(pars$nPatches==1){
lines(time, Y, col=Yclrs[1], lty = llty[1])
lines(time, Z, col=Zclrs[1], lty = llty[1])
}
if(pars$nPatches>1){
if (length(Yclrs)==1) Yclrs=rep(Yclrs, pars$nPatches)
if (length(Zclrs)==1) Zclrs=rep(Zclrs, pars$nPatches)
if (length(llty)==1) llty=rep(llty, pars$nPatches)

for(i in 1:pars$nPatches){
lines(time, Y[,i], col=Yclrs[i], lty = llty[i])
lines(time, Z[,i], col=Zclrs[i], lty = llty[i])
}
}
})}

#' Plot the fraction of infected and infective mosquitoes
#'
#' @param pars a [list] that defines an `exDE` model (*e.g.*, generated by `xde_setup()`)
#' @param Yclrs a [character] vector of colors for infected mosquitoes
#' @param Zclrs a [character] vector of colors for infective mosquitoes
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#' @param stable a [logical] set to FALSE for `orbits` and TRUE for `stable_orbits`
#' @param add_axes a [logical] to plot axes only if TRUE
#'
#' @export
xde_plot_YZ_fracs = function(pars, Yclrs = "purple", Zclrs = "darkred", llty=1, stable=FALSE, add_axes=TRUE){
vars=with(pars$outputs,if(stable==TRUE){stable_orbits}else{orbits})

if(add_axes == TRUE)
with(vars$MYZ,
plot(time, 0*time, type = "n", ylim = range(0,1),
ylab = "Fraction Infected", xlab = "Time"))

xde_lines_YZ_fracs(vars$MYZ, pars, Yclrs, Zclrs, llty)
}

#' Add lines for the fraction of infected and infective mosquitoes
#'
#' @param MYZ a [list] the output of `exDE::parse_deout()`
#' @param pars a [list] specifying the model
#' @param Yclrs a [list] of colors
#' @param Zclrs a [list] of colors
#' @param llty an [integer] (or integers) to set the `lty` for plotting
#'
#' @export
xde_lines_YZ_fracs = function(MYZ, pars, Yclrs="purple", Zclrs="darkred", llty=1){
with(MYZ,{
if(pars$nPatches==1) {
lines(time, y, col=Yclrs, lty = llty[1])
lines(time, z, col=Zclrs, lty = llty[1])
}
if(pars$nPatches>1){
if (length(Yclrs)==1) Yclrs=rep(Yclrs, pars$nPatches)
if (length(Zclrs)==1) Zclrs=rep(Zclrs, pars$nPatches)
if (length(llty)==1) llty=rep(llty, pars$nPatches)

for(i in 1:pars$nPatches){
lines(time, y[,i], col=Yclrs[i], lty = llty[i])
lines(time, z[,i], col=Zclrs[i], lty = llty[i])
}
}
})}
Loading