From 1812a2ee5b9e2562dc3322033898ef522ec69abc Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 3 Oct 2024 15:58:52 -0700 Subject: [PATCH 1/2] Cleanup documentation; renaming functions make_Lpar* was renamed setup_Lpar create_Lpar* was renamed make_Lpar make_Linits* was renamed setup_Linits create_Linits* was renamed make_Linits make_indices_L was renamed setup_indices_L --- NAMESPACE | 26 +- R/adult-interface.R | 26 +- R/aquatic-basicL.R | 259 +++++++++--------- R/aquatic-interface.R | 96 +++---- R/aquatic-trivial.R | 207 +++++++------- R/utils.R | 2 +- R/xds_setup.R | 20 +- _pkgdown.yml | 24 +- docs/pkgdown.yml | 2 +- docs/reference/F_emerge.basicL.html | 4 +- docs/reference/create_Lpar_basicL.html | 4 +- docs/reference/dLdt.basicL.html | 4 +- docs/reference/index.html | 12 +- docs/reference/make_Lpar.basicL.html | 4 +- man/F_emerge.Rd | 2 +- man/F_emerge.basicL.Rd | 10 +- man/F_emerge.trivial.Rd | 2 +- man/LBaseline.basicL.Rd | 2 +- man/LBaseline.trivial.Rd | 2 +- man/LBionomics.basicL.Rd | 2 +- man/LBionomics.trivial.Rd | 2 +- man/Update_Lt.Rd | 2 +- man/Update_Lt.basicL.Rd | 4 +- man/Update_Lt.trivial.Rd | 2 +- man/create_Lpar_trivial.Rd | 31 --- man/dLdt.Rd | 2 +- man/dLdt.basicL.Rd | 4 +- man/dLdt.trivial.Rd | 2 +- man/get_Linits.Rd | 4 +- man/get_Lpars.basicL.Rd | 4 +- man/get_Lpars.trivial.Rd | 4 +- man/list_Lvars.Rd | 2 +- man/list_Lvars.basicL.Rd | 2 +- man/list_Lvars.trivial.Rd | 2 +- ...Linits_basicL.Rd => make_Linits_basicL.Rd} | 8 +- ...ate_Lpar_basicL.Rd => make_Lpar_basicL.Rd} | 10 +- man/make_Lpar_trivial.Rd | 36 +++ man/make_indices_L.trivial.Rd | 19 -- man/parse_Lorbits.trivial.Rd | 6 +- man/put_Lvars.Rd | 23 -- man/put_Lvars.trivial.Rd | 23 -- man/set_Linits.Rd | 9 +- man/set_Linits.basicL.Rd | 2 +- man/set_Linits.trivial.Rd | 4 +- man/set_Lpars.basicL.Rd | 2 +- man/set_Lpars.trivial.Rd | 5 +- man/{make_Linits.Rd => setup_Linits.Rd} | 8 +- ...inits.basicL.Rd => setup_Linits.basicL.Rd} | 12 +- ...its.trivial.Rd => setup_Linits.trivial.Rd} | 6 +- man/{make_Lpar.Rd => setup_Lpar.Rd} | 10 +- ...ke_Lpar.basicL.Rd => setup_Lpar.basicL.Rd} | 12 +- ..._Lpar.trivial.Rd => setup_Lpar.trivial.Rd} | 8 +- man/{make_indices_L.Rd => setup_indices_L.Rd} | 6 +- ..._L.basicL.Rd => setup_indices_L.basicL.Rd} | 8 +- man/setup_indices_L.trivial.Rd | 19 ++ man/update_Linits.Rd | 5 +- man/update_Linits.trivial.Rd | 6 +- man/xde_steady_state_L.basicL.Rd | 2 +- man/xde_steady_state_L.trivial.Rd | 4 +- tests/testthat/.test-metrics.R.swp | Bin 0 -> 12288 bytes vignettes/GettingStarted.Rmd | 2 +- vignettes/adult_RM.Rmd | 4 +- vignettes/aqua_basic.Rmd | 4 +- vignettes/aqua_trace.Rmd | 4 +- vignettes/ex_534.Rmd | 6 +- vignettes/human_sis.Rmd | 4 +- 66 files changed, 513 insertions(+), 541 deletions(-) delete mode 100644 man/create_Lpar_trivial.Rd rename man/{create_Linits_basicL.Rd => make_Linits_basicL.Rd} (65%) rename man/{create_Lpar_basicL.Rd => make_Lpar_basicL.Rd} (82%) create mode 100644 man/make_Lpar_trivial.Rd delete mode 100644 man/make_indices_L.trivial.Rd delete mode 100644 man/put_Lvars.Rd delete mode 100644 man/put_Lvars.trivial.Rd rename man/{make_Linits.Rd => setup_Linits.Rd} (67%) rename man/{make_Linits.basicL.Rd => setup_Linits.basicL.Rd} (56%) rename man/{make_Linits.trivial.Rd => setup_Linits.trivial.Rd} (77%) rename man/{make_Lpar.Rd => setup_Lpar.Rd} (73%) rename man/{make_Lpar.basicL.Rd => setup_Lpar.basicL.Rd} (65%) rename man/{make_Lpar.trivial.Rd => setup_Lpar.trivial.Rd} (71%) rename man/{make_indices_L.Rd => setup_indices_L.Rd} (84%) rename man/{make_indices_L.basicL.Rd => setup_indices_L.basicL.Rd} (66%) create mode 100644 man/setup_indices_L.trivial.Rd create mode 100644 tests/testthat/.test-metrics.R.swp diff --git a/NAMESPACE b/NAMESPACE index ccc1bae96..9f4629b9c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -218,10 +218,6 @@ S3method(list_MYZvars,SI) S3method(list_MYZvars,basicM) S3method(list_MYZvars,macdonald) S3method(list_Xvars,SIS) -S3method(make_Linits,basicL) -S3method(make_Linits,trivial) -S3method(make_Lpar,basicL) -S3method(make_Lpar,trivial) S3method(make_MYZinits,GeRM) S3method(make_MYZinits,RM_dts) S3method(make_MYZinits,SI) @@ -255,8 +251,6 @@ S3method(make_function,sharkfin) S3method(make_function,sigmoid) S3method(make_function,sin) S3method(make_function,sum) -S3method(make_indices_L,basicL) -S3method(make_indices_L,trivial) S3method(make_indices_MYZ,GeRM) S3method(make_indices_MYZ,RM_dts) S3method(make_indices_MYZ,SI) @@ -276,7 +270,6 @@ S3method(parse_MYZorbits,trivial) S3method(parse_Xorbits,SIS) S3method(parse_Xorbits,hMoI) S3method(parse_Xorbits,trivial) -S3method(put_Lvars,trivial) S3method(put_MYZvars,RM_dts) S3method(put_MYZvars,SI) S3method(put_Xvars,SIS) @@ -302,6 +295,10 @@ S3method(set_Xpars,hMoI) S3method(set_Xpars,trivial) S3method(set_eir,cohort) S3method(setup_EIP,fixedlag_dts) +S3method(setup_Linits,basicL) +S3method(setup_Linits,trivial) +S3method(setup_Lpar,basicL) +S3method(setup_Lpar,trivial) S3method(setup_development,func) S3method(setup_exposure_nb,dts) S3method(setup_exposure_nb,xde) @@ -309,6 +306,8 @@ S3method(setup_exposure_pois,dts) S3method(setup_exposure_pois,xde) S3method(setup_humidity,func) S3method(setup_hydrology,func) +S3method(setup_indices_L,basicL) +S3method(setup_indices_L,trivial) S3method(setup_rainfall,func) S3method(setup_shock,func) S3method(setup_temperature,func) @@ -447,9 +446,6 @@ export(compute_calU) export(compute_eggs_laid) export(compute_kappa) export(compute_local_frac) -export(create_Linits_basicL) -export(create_Lpar_basicL) -export(create_Lpar_trivial) export(create_MYZinits_GeRM) export(create_MYZinits_RM_dts) export(create_MYZinits_SI) @@ -520,8 +516,9 @@ export(list_Xvars) export(list_vars) export(make_EIR) export(make_EIR_full) -export(make_Linits) -export(make_Lpar) +export(make_Linits_basicL) +export(make_Lpar_basicL) +export(make_Lpar_trivial) export(make_MYZinits) export(make_MYZpar) export(make_Omega) @@ -539,7 +536,6 @@ export(make_calU) export(make_eggs_laid) export(make_function) export(make_indices) -export(make_indices_L) export(make_indices_MYZ) export(make_kappa) export(make_local_frac) @@ -560,7 +556,6 @@ export(parse_MYZorbits) export(parse_Xorbits) export(parse_orbits) export(parse_y) -export(put_Lvars) export(put_MYZvars) export(put_Xvars) export(reset_state) @@ -579,6 +574,8 @@ export(setup_BLOOD_FEEDING) export(setup_EGG_LAYING) export(setup_EIP) export(setup_Hpar_static) +export(setup_Linits) +export(setup_Lpar) export(setup_TRANSMISSION) export(setup_care_seeking_no_behavior) export(setup_development) @@ -592,6 +589,7 @@ export(setup_humidity) export(setup_humidity_func) export(setup_hydrology) export(setup_hydrology_func) +export(setup_indices_L) export(setup_no_active_case_detection) export(setup_no_area_spray) export(setup_no_bednets) diff --git a/R/adult-interface.R b/R/adult-interface.R index e80eef919..1d82d8db7 100644 --- a/R/adult-interface.R +++ b/R/adult-interface.R @@ -15,6 +15,20 @@ dMYZdt <- function(t, y, pars, s) { UseMethod("dMYZdt", pars$MYZpar[[s]]) } + +#' @title Derivatives for adult mosquitoes +#' @description This method dispatches on the type of `pars$MYZpar`. +#' @param t current simulation time +#' @param y state vector +#' @param pars a [list] +#' @param s the species index +#' @return the derivatives a [vector] +#' @export +Update_MYZt <- function(t, y, pars, s) { + UseMethod("Update_MYZt", pars$MYZpar[[s]]) +} + + #' @title Adult Mosquito - Baseline Bionomics #' @description Compute adult mosquito bionomics as a #' *changing baseline.* @@ -84,18 +98,6 @@ MYZ_rates2probs = function(MYZpar, runtime){ UseMethod("MYZ_rates2probs", MYZpar) } -#' @title Derivatives for adult mosquitoes -#' @description This method dispatches on the type of `pars$MYZpar`. -#' @param t current simulation time -#' @param y state vector -#' @param pars a [list] -#' @param s the species index -#' @return the derivatives a [vector] -#' @export -Update_MYZt <- function(t, y, pars, s) { - UseMethod("Update_MYZt", pars$MYZpar[[s]]) -} - #' @title Compute the steady states as a function of the daily EIR #' @description This method dispatches on the type of `MYZpar`. #' @inheritParams xde_steady_state_MYZ diff --git a/R/aquatic-basicL.R b/R/aquatic-basicL.R index 01a8f8a5a..43935310a 100644 --- a/R/aquatic-basicL.R +++ b/R/aquatic-basicL.R @@ -1,6 +1,6 @@ # the aquatic mosquito `basicL` competition model -#' @title **L** Component Derivatives for `basicL` +#' @title Derivatives for `basicL` (**L** Component) #' @description #' This implements differential equation model for aquatic mosquito ecology. #' The equations have been modified slightly from a version published by @@ -29,7 +29,7 @@ #' @inheritParams dLdt #' @return a [numeric] vector #' @references{\insertRef{SmithDL2013LarvalDynamics}{ramp.xds} } -#' @seealso [create_Lpar_basicL] +#' @seealso [make_Lpar_basicL] #' @export dLdt.basicL <- function(t, y, pars, s) { eta <- as.vector(pars$eggs_laid[[s]]) @@ -42,20 +42,78 @@ dLdt.basicL <- function(t, y, pars, s) { }) } -#' @title Set up `Lpar` for the `basicL` model + +#' @title Update State Variables for `basicL` (**L** Component) +#' @description Implements [Update_Lt] for the `basicL` competition model. +#' @inheritParams Update_Lt +#' @return a [numeric] vector +#' @export +Update_Lt.basicL <- function(t, y, pars, s) { + eta <- pars$eggs_laid[[s]] + with(list_Lvars(y, pars, s),{ + L <- y[L_ix] + with(pars$Lpar[[s]], { + Lt = eta + (1-exp(-(psi+xi*L)))*exp(-(phi+theta*L))*L + return(Lt) + }) + }) +} + +#' @title Compute Emergent Adults for `basicL` (**L** Component) +#' @description The number of adults emerging from the habitats, +#' per day, is: +#' \deqn{\psi e^{-\xi L} L.} +#' @inheritParams F_emerge +#' @return a [numeric] vector of length `nHabitats` +#' @seealso [dLdt.basicL] +#' @export +F_emerge.basicL <- function(t, y, pars, s) { + L <- y[pars$ix$L[[s]]$L_ix] + with(pars$Lpar[[s]],{ + return(psi*exp(-xi*L)*L) + }) +} + +#' @title Baseline Bionomics for `basicL` (**L** Component) +#' @description Set **L** component parameters +#' to baseline values for `basicL` +#' @inheritParams LBaseline +#' @return a **`ramp.xds`** object +#' @export +LBaseline.basicL <- function(t, y, pars, s) { + with(pars$Lpar[[s]],{ + pars$Lpar[[s]]$es_psi <- rep(1, nHabitats) + pars$Lpar[[s]]$es_phi <- rep(1, nHabitats) + return(pars) +})} + +#' @title Bionomics for `basicL` (**L** Component) +#' @description Implements [LBionomics] for the `basicL` +#' @inheritParams LBionomics +#' @return a **`ramp.xds`** object +#' @export +LBionomics.basicL <- function(t, y, pars, s) { + with(pars$Lpar[[s]],{ + pars$Lpar[[s]]$psi <- psi_t*es_psi + pars$Lpar[[s]]$phi <- phi_t*es_phi + return(pars) +})} + + +#' @title Setup `Lpar` for `basicL` (**L** Component) #' @description The function sets up `Lpar` for the \eqn{s^{th}} species -#' by calling [create_Lpar_basicL] -#' @inheritParams make_Lpar +#' by calling [make_Lpar_basicL] +#' @inheritParams setup_Lpar #' @return an **`xds`** object -#' @seealso [create_Lpar_basicL] +#' @seealso [make_Lpar_basicL] #' @export -make_Lpar.basicL = function(Lname, pars, s, Lopts=list()){ - pars$Lpar[[s]] = create_Lpar_basicL(pars$nHabitats, Lopts) +setup_Lpar.basicL = function(Lname, pars, s, Lopts=list()){ + pars$Lpar[[s]] = make_Lpar_basicL(pars$nHabitats, Lopts) pars <- LBionomics(0, 0, pars, s) return(pars) } -#' @title Create `Lpar` for `basicL` +#' @title Make `Lpar` for `basicL` (**L** Component) #' @description The following parameters will be set to the values in #' `Lopts.` If they are not found, default values will be used. #' @@ -70,10 +128,10 @@ make_Lpar.basicL = function(Lname, pars, s, Lopts=list()){ #' @param xi delayed maturation in response to mean crowding #' @param phi density-independent mortality rates for each aquatic habitat #' @param theta density-dependent mortality terms for each aquatic habitat -#' @seealso Called by: [make_Lpar.basicL]. Related: [dLdt.basicL] & [Update_Lt.basicL] +#' @seealso Called by: [setup_Lpar.basicL]. Related: [dLdt.basicL] & [Update_Lt.basicL] #' @return **`Lpar`** an **L** component object #' @export -create_Lpar_basicL = function(nHabitats, Lopts=list(), psi=1/8, xi=0, phi=1/8, theta=1/100){ +make_Lpar_basicL = function(nHabitats, Lopts=list(), psi=1/8, xi=0, phi=1/8, theta=1/100){ with(Lopts,{ Lpar = list() class(Lpar) <- "basicL" @@ -88,13 +146,12 @@ create_Lpar_basicL = function(nHabitats, Lopts=list(), psi=1/8, xi=0, phi=1/8, t }) } - -#' @title Get **L** component parameters +#' @title Get **L** Component Parameters for `basicL` #' @description Get the **L** component parameters #' @param pars an **`xds`** object #' @param s the vector species index #' @return a [list] -#' @seealso [dLdt.basicL] +#' @seealso [dLdt.basicL] or [set_Lpars.basicL] #' @export get_Lpars.basicL <- function(pars, s=1) { with(pars$Lpar[[s]], list( @@ -109,7 +166,7 @@ get_Lpars.basicL <- function(pars, s=1) { #' - `phi` or \eqn{\phi} #' - `theta` or \eqn{\theta} #' @inheritParams set_Lpars -#' @seealso [dLdt.basicL] or [create_Lpar_basicL] +#' @seealso [dLdt.basicL] or [make_Lpar_basicL] #' @return an **`xds`** object #' @export set_Lpars.basicL <- function(pars, s=1, Lopts=list()) { @@ -123,82 +180,33 @@ set_Lpars.basicL <- function(pars, s=1, Lopts=list()) { }))} -#' @title Compute the Steady State for [dLdt.basicL] -#' @description Given an egg deposition rate `eta,` -#' return a steady state value for the equations in [dLdt.basicL] -#' @note This function does not use deSolve -#' @inheritParams xde_steady_state_L -#' @return the values of \eqn{L} at the steady state -#' @importFrom stats nlm -#' @export -xde_steady_state_L.basicL = function(eta, Lpar){ - dL <- function(L, eta, Lpar){with(Lpar,{ - sum((eta - (psi*exp(-xi*L) + phi + (theta*L))*L)^2) - })} - L=nlm(dL, eta, Lpar=Lpar, eta=eta)$estimate - list(L=L) -} -#' @title Update **L** Component Variables for `basicL` -#' @description Implements [Update_Lt] for the basicL competition model. -#' @inheritParams Update_Lt -#' @return a [numeric] vector -#' @export -Update_Lt.basicL <- function(t, y, pars, s) { - eta <- pars$eggs_laid[[s]] - with(list_Lvars(y, pars, s),{ - L <- y[L_ix] - with(pars$Lpar[[s]], { - Lt = eta + (1-exp(-psi*exp(-xi*L)))*exp(-(phi+theta*L))*L - return(Lt) - }) - }) -} - -#' @title Compute emergent adults -#' @description The function computes the number of -#' emergent adults from aquatic habitats for `basicL` -#' @inheritParams F_emerge -#' @return a [numeric] vector of length `nHabitats` +#' @title Setup Initial Values for `basicL` (**L** Component) +#' @description This sets initial values of the variable \eqn{L} by +#' calling [make_Linits_basicL]. Default values are used unless other values +#' are passed in `Lopts` by name (*i.e.* `Lopts$L`) +#' @inheritParams setup_Linits +#' @seealso [make_Linits_basicL] +#' @return a [list] #' @export -F_emerge.basicL <- function(t, y, pars, s) { - L <- y[pars$ix$L[[s]]$L_ix] - with(pars$Lpar[[s]],{ - return(psi*exp(-xi*L)*L) - }) +setup_Linits.basicL = function(pars, s, Lopts=list()){ + pars$Linits[[s]] = make_Linits_basicL(pars$nHabitats, Lopts) + return(pars) } - - - -#' @title Reset **L** Component Parameters to Baseline -#' @description Set **L** component parameters -#' to baseline values for `basicL` -#' @inheritParams LBaseline -#' @return a **`ramp.xds`** object +#' @title Make Initial Values for `basicL` (**L** Component) +#' @description Initial values of the variable \eqn{L} can be set +#' @param nHabitats the number of habitats in the model +#' @param Lopts a [list] that overwrites default values +#' @param L initial conditions +#' @return a [list] with Linits added #' @export -LBaseline.basicL <- function(t, y, pars, s) { - with(pars$Lpar[[s]],{ - pars$Lpar[[s]]$es_psi <- rep(1, nHabitats) - pars$Lpar[[s]]$es_phi <- rep(1, nHabitats) - return(pars) +make_Linits_basicL = function(nHabitats, Lopts=list(), L=1){with(Lopts,{ + L = checkIt(L, nHabitats) + return(list(L=L)) })} -#' @title Modify **L** Component Parameters -#' @description Implements [LBionomics] for the `basicL` -#' @inheritParams LBionomics -#' @return a **`ramp.xds`** object -#' @export -LBionomics.basicL <- function(t, y, pars, s) { - with(pars$Lpar[[s]],{ - pars$Lpar[[s]]$psi <- psi_t*es_psi - pars$Lpar[[s]]$phi <- phi_t*es_phi - return(pars) - })} - - - -#' @title List **L** Component Variables +#' @title List **L** Component Variables for `basicL` #' @description Extract the **L** component variables from the #' vector of state variables (`y`) and return them as a named list #' @inheritParams list_Lvars @@ -211,21 +219,7 @@ list_Lvars.basicL <- function(y, pars, s){ ))) } - -#' @title Setup the Initial Values for **L** Component Variables for `basicL` -#' @description This sets initial values of the variable \eqn{L} by -#' calling [create_Linits_basicL]. Default values are used unless other values -#' are passed in `Lopts` by name (*i.e.* `Lopts$L`) -#' @inheritParams make_Linits -#' @seealso [create_Linits_basicL] -#' @return a [list] -#' @export -make_Linits.basicL = function(pars, s, Lopts=list()){ - pars$Linits[[s]] = create_Linits_basicL(pars$nHabitats, Lopts) - return(pars) -} - -#' @title Set the Initial Values for **L** Component Variables for `basicL` +#' @title Set the Initial Values for `basicL` (**L** Component) #' @description Initial values of the variable \eqn{L} are reset if they are #' passed as a named component of `Lopts` #' @inheritParams set_Linits @@ -249,38 +243,14 @@ update_Linits.basicL <- function(pars, y, s) { return(pars) } -#' @title Create Initial Values for **L** Component Variables for `basicL` -#' @description Initial values of the variable \eqn{L} can be set -#' @param nHabitats the number of habitats in the model -#' @param Lopts a [list] that overwrites default values -#' @param L initial conditions -#' @return a [list] with Linits added -#' @export -create_Linits_basicL = function(nHabitats, Lopts=list(), L=1){with(Lopts,{ - L = checkIt(L, nHabitats) - return(list(L=L)) -})} - -#' @title Parse **L** Component Variables for `basicL` -#' @description The function returns the column representing -#' the variable \eqn{L} from a matrix where each row is a state variable. -#' The variale is returned as a named list. -#' @inheritParams parse_Lorbits -#' @return a named [list] -#' @export -parse_Lorbits.basicL <- function(outputs, pars, s) { - L = outputs[,pars$ix$L[[s]]$L_ix] - return(list(L=L)) -} - -#' @title Make Indices for **L** Component Variables for `basicL` +#' @title Setup Variable Indices for `basicL` (**L** Component) #' @description Set the values of the indices for the **L** component variables #' for the `basicL` module -#' @inheritParams make_indices_L +#' @inheritParams setup_indices_L #' @return an **`xds`** object #' @importFrom utils tail #' @export -make_indices_L.basicL <- function(pars, s) {with(pars,{ +setup_indices_L.basicL <- function(pars, s) {with(pars,{ L_ix <- seq(from = max_ix+1, length.out = nHabitats) max_ix <- tail(L_ix, 1) @@ -292,4 +262,41 @@ make_indices_L.basicL <- function(pars, s) {with(pars,{ return(pars) })} +#' @title Parse **L** Component Variables for `basicL` +#' @description The function returns the column representing +#' the variable \eqn{L} from a matrix where each row is a state variable. +#' The variable is returned as a named list. +#' @inheritParams parse_Lorbits +#' @return a named [list] +#' @export +parse_Lorbits.basicL <- function(outputs, pars, s) { + L = outputs[,pars$ix$L[[s]]$L_ix] + return(list(L=L)) +} + +#' @title Set **L** Component Initial Values +#' @param pars an **`xds`** object +#' @param s the vector species index +#' @param Lopts a named list +#' @return an `xds` object +#' @export +set_Linits <- function(pars, s=1, Lopts=list()) { + UseMethod("set_Linits", pars$Lpar[[s]]) +} + +#' @title Compute the Steady State of `dLdt.basicL` (**L** Component) +#' @description Given an egg deposition rate `eta,` +#' return a steady state value for the equations in [dLdt.basicL] +#' @note This function does not use deSolve +#' @inheritParams xde_steady_state_L +#' @return the values of \eqn{L} at the steady state +#' @importFrom stats nlm +#' @export +xde_steady_state_L.basicL = function(eta, Lpar){ + dL <- function(L, eta, Lpar){with(Lpar,{ + sum((eta - (psi*exp(-xi*L) + phi + (theta*L))*L)^2) + })} + L=nlm(dL, eta, Lpar=Lpar, eta=eta)$estimate + list(L=L) +} diff --git a/R/aquatic-interface.R b/R/aquatic-interface.R index 4b4eb65f6..d06f3401e 100644 --- a/R/aquatic-interface.R +++ b/R/aquatic-interface.R @@ -1,6 +1,6 @@ # generic methods for aquatic component -#' @title **L** Component Derivatives +#' @title Derivatives for an **L** Component Module #' @description This method computes and returns the derivatives #' for the **L** Component modules #' @note Dispatches on the class of `pars$Lpar[[s]]` @@ -14,7 +14,7 @@ dLdt <- function(t, y, pars, s) { UseMethod("dLdt", pars$Lpar[[s]]) } -#' @title Update States for **L** +#' @title Update State Variables for an **L** Component Module #' @description This method updates the state variables #' for **L** Component modules #' @note Dispatches on the class of `pars$Lpar[[s]]` @@ -54,12 +54,26 @@ LBionomics <- function(t, y, pars, s) { UseMethod("LBionomics", pars$Lpar[[s]]) } +#' @title Compute Emergent Adults +#' @description This function computes the rate or number of emerging adults: a +#' rate for differential equations, or a number for difference equations. +#' @note This method dispatches on the class of `pars$Lpar[[s]]` +#' @param t current simulation time +#' @param y state vector +#' @param pars an **`xds`** object +#' @param s the species index +#' @return a [numeric] vector of length `nHabitats` +#' @export +F_emerge <- function(t, y, pars, s) { + UseMethod("F_emerge", pars$Lpar[[s]]) +} + #' @title Set up `Lpar` for **L** Component modules #' @description -#' Each instance of `make_Lpar` calls a function (usually `create_Lpar_*`) that +#' Each instance of `setup_Lpar.*` calls a function `create_Lpar_*` that #' creates an object **`Lpar`.** #' It is attached the **`xds`** object as `pars$Lpar[[s]].` Each instance of `create_Lpar_*` -#' should assign default parameter values. These will be over-written by `Lopts` +#' should assign default parameter values that will be over-written by `Lopts` #' @note This method assigns `Lname` to class(`Lname`) and dispatches on `Lname`. #' @param Lname the class name of the aquatic model #' @param pars an **`xds`** object @@ -67,9 +81,9 @@ LBionomics <- function(t, y, pars, s) { #' @param Lopts a named [list] to configure **`Lpar`** #' @return an **`xds`** object #' @export -make_Lpar = function(Lname, pars, s, Lopts=list()){ +setup_Lpar = function(Lname, pars, s, Lopts=list()){ class(Lname) <- Lname - UseMethod("make_Lpar", Lname) + UseMethod("setup_Lpar", Lname) } #' @title Get parameters for the **L** Component module @@ -91,32 +105,7 @@ set_Lpars <- function(pars, s=1, Lopts=list()) { UseMethod("set_Lpars", pars$Lpar[[s]]) } - -#' @title Set **L** Component Initial Values -#' @param pars an **`xds`** object -#' @param s the vector species index -#' @param Lopts a named list -#' @return an `xds` object -#' @export -set_Linits <- function(pars, s=1, Lopts=list()) { - UseMethod("set_Linits", pars$Lpar[[s]]) -} - -#' @title Emerging adults -#' @description This function computes the rate or number of emerging adults: a -#' rate for differential equations, or a number for difference equations. -#' @note This method dispatches on the class of `pars$Lpar[[s]]` -#' @param t current simulation time -#' @param y state vector -#' @param pars an **`xds`** object -#' @param s the species index -#' @return a [numeric] vector of length `nHabitats` -#' @export -F_emerge <- function(t, y, pars, s) { - UseMethod("F_emerge", pars$Lpar[[s]]) -} - -#' @title Return **L** Component Variables as a list +#' @title List **L** Component Variables #' @description Extract the variables describing **L** Component #' states for the \eqn{s^{th}} species and return them as a named list #' @note This method dispatches on the class of `pars$Lpar[[s]]`. @@ -129,30 +118,18 @@ list_Lvars <- function(y, pars, s) { UseMethod("list_Lvars", pars$Lpar[[s]]) } -#' @title Put Lvars in place of the L variables in y -#' @description This method dispatches on the class of `pars$Lpar[[s]]`. -#' @param Lvars the L variables to insert into y -#' @param y the variables -#' @param pars an **`xds`** object -#' @param s the vector species index -#' @return an **`xds`** object -#' @export -put_Lvars <- function(Lvars, y, pars, s) { - UseMethod("put_Lvars", pars$Lpar[[s]]) -} - -#' @title Set up Initial Values of Variables for **L** Component modules +#' @title Setup Initial Values for the **L** Component #' @description This method dispatches on `Lname`. #' @param pars an **`xds`** object #' @param s the species index #' @param Lopts a [list] #' @return an **`xds`** object #' @export -make_Linits = function(pars, s, Lopts=list()){ - UseMethod("make_Linits", pars$Lpar[[s]]) +setup_Linits = function(pars, s, Lopts=list()){ + UseMethod("setup_Linits", pars$Lpar[[s]]) } -#' @title Get the stored initial values +#' @title Get Initial Values for the **L** Component #' @note This method dispatches on the class of `pars$Lpar`. #' @param pars an **`xds`** object #' @param s the species index @@ -162,7 +139,24 @@ get_Linits <- function(pars, s=1) { pars$Linits[[s]] } -#' @title Set Initial Values for the **L** Component Module from a State Vector +#' @title Set **L** Component Initial Values +#' @description +#' This sets initial values for an **L** Component +#' module from a named list +#' @param pars an **`xds`** object +#' @param s the vector species index +#' @param Lopts a named list +#' @return an `xds` object +#' @export +set_Linits <- function(pars, s=1, Lopts=list()) { + UseMethod("set_Linits", pars$Lpar[[s]]) +} + +#' @title Update **L** Component Initial Values +#' @description +#' This sets initial values for an **L** Component +#' module from a state variables vector \eqn{y} +#' #' @param pars an **`xds`** object #' @param y the state variables #' @param s the species index @@ -177,8 +171,8 @@ update_Linits <- function(pars, y, s) { #' @param s the species index #' @return an **`xds`** object #' @export -make_indices_L <- function(pars, s) { - UseMethod("make_indices_L", pars$Lpar[[s]]) +setup_indices_L <- function(pars, s) { + UseMethod("setup_indices_L", pars$Lpar[[s]]) } #' @title Parse **L** Component Outputs diff --git a/R/aquatic-trivial.R b/R/aquatic-trivial.R index f5eb532f7..9f3e9a656 100644 --- a/R/aquatic-trivial.R +++ b/R/aquatic-trivial.R @@ -1,6 +1,24 @@ # specialized methods for the aquatic mosquito trivial model -#' @title Number of newly emerging adults from each larval habitat +#' @title Derivatives for `trivial` (**L** Component) +#' @description Return a numeric vector of length 0 +#' @inheritParams dLdt +#' @return an empty [list] +#' @export +dLdt.trivial <- function(t, y, pars, s) { + return(numeric(0)) +} + +#' @title Update State Variables for `trivial` (**L** Component) +#' @description Implements [Update_Lt] for the trivial (forced emergence) model. +#' @inheritParams Update_Lt +#' @return a [numeric] vector +#' @export +Update_Lt.trivial <- function(t, y, pars, s) { + return(list()) +} + +#' @title Compute Emergent Adults for `trivial` (**L** Component) #' @description The number of emerging adults is a function \deqn{\Lambda S(t) T(t)} where #' + \eqn{\Lambda} or `Lambda` is the mean number of adult female mosquitoes emerging per day #' + \eqn{S(t)} or `F_season` is a seasonal signal (ideally, with an average annual mean of 1) @@ -13,44 +31,40 @@ F_emerge.trivial <- function(t, y, pars, s) {with(pars$Lpar[[s]],{ return(emergents) })} -#' @title Return the parameters as a list -#' @description This method dispatches on the type of `pars$Lpar[[s]]`. -#' @param pars an **`xds`** object -#' @param s the vector species index -#' @return a [list] +#' @title Baseline Bionomics for `trivial` (**L** Component) +#' @description Implements [LBaseline] for the RM model +#' @inheritParams LBaseline +#' @return a named [list] #' @export -get_Lpars.trivial <- function(pars, s=1) { - with(pars$Lpar[[s]], list( - Lambda=Lambda, - F_season=F_season, - F_trend=F_trend - )) +LBaseline.trivial<- function(t, y, pars, s) { + return(pars) } -#' @title Return the parameters as a list -#' @description This method dispatches on the type of `pars$Lpar[[s]]`. -#' @inheritParams set_Lpars +#' @title Bionomics for `trivial` (**L** Component) +#' @description Implements [LBionomics] for the RM model +#' @inheritParams LBionomics #' @return an **`xds`** object #' @export -set_Lpars.trivial <- function(pars, s=1, Lopts=list()) { - nHabitats <- pars$nHabitats - with(pars$Lpar[[s]], with(Lopts,{ - pars$Lpar[[s]]$Lambda = Lambda - pars$Lpar[[s]]$F_season = F_season - pars$Lpar[[s]]$F_trend = F_trend - return(pars) - }))} +LBionomics.trivial <- function(t, y, pars, s) { + return(pars) +} -#' @title Return the parameters as a list -#' @description This method dispatches on the type of `pars$Lpar[[s]]`. -#' @inheritParams set_Linits -#' @return an **`xds`** object +#' @title Setup `Lpar` for the `trivial` module +#' @description Implements [setup_Lpar] for the trivial model +#' @inheritParams setup_Lpar +#' @return a [list] vector #' @export -set_Linits.trivial <- function(pars, s=1, Lopts=list()) { +setup_Lpar.trivial = function(Lname, pars, s, Lopts=list()){ + pars$Lpar[[s]] = make_Lpar_trivial(pars$nHabitats, Lopts) return(pars) } -#' @title Make parameters for trivial aquatic mosquito model + +#' @title Make `Lpar` for `trivial` (**L** Component) +#' @description The number of emerging adults is a function \deqn{\Lambda S(t) T(t)} where +#' + \eqn{\Lambda} or `Lambda` is the mean number of adult female mosquitoes emerging per day +#' + \eqn{S(t)} or `F_season` is a seasonal signal (ideally, with an average annual mean of 1) +#' + \eqn{T(t)} or `F_trend` is a function returning a trend (ideally, with an average value of 1) #' @param nHabitats the number of habitats in the model #' @param Lopts a [list] that overwrites default values #' @param Lambda vector of mean emergence rates from each aquatic habitat @@ -58,9 +72,9 @@ set_Linits.trivial <- function(pars, s=1, Lopts=list()) { #' @param F_trend a F_trend function #' @return none #' @export -create_Lpar_trivial = function(nHabitats, Lopts=list(), - Lambda=1000, - F_season=F_flat, F_trend=F_flat){ +make_Lpar_trivial = function(nHabitats, Lopts=list(), + Lambda=1000, + F_season=F_flat, F_trend=F_flat){ with(Lopts,{ Lpar = list() class(Lpar) <- "trivial" @@ -70,43 +84,48 @@ create_Lpar_trivial = function(nHabitats, Lopts=list(), return(Lpar) })} -#' @title Reset aquatic parameters to baseline -#' @description Implements [LBaseline] for the RM model -#' @inheritParams LBaseline -#' @return a named [list] + +#' @title Get **L** Component Parameters for `trivial` +#' @description Show the trace function +#' @param pars an **`xds`** object +#' @param s the vector species index +#' @return a [list] #' @export -LBaseline.trivial<- function(t, y, pars, s) { - return(pars) +get_Lpars.trivial <- function(pars, s=1) { + with(pars$Lpar[[s]], list( + Lambda=Lambda, + F_season=F_season, + F_trend=F_trend + )) } -#' @title Reset aquatic parameters to baseline -#' @description Implements [LBionomics] for the RM model -#' @inheritParams LBionomics +#' @title Set **L** Component parameters for `trivial` +#' @description If `Lambda` or `F_season` or `F_trend` +#' are named in a list `Lopts`, the old value is replaced +#' @inheritParams set_Lpars #' @return an **`xds`** object #' @export -LBionomics.trivial <- function(t, y, pars, s) { - return(pars) -} +set_Lpars.trivial <- function(pars, s=1, Lopts=list()) { + nHabitats <- pars$nHabitats + with(pars$Lpar[[s]], with(Lopts,{ + pars$Lpar[[s]]$Lambda = Lambda + pars$Lpar[[s]]$F_season = F_season + pars$Lpar[[s]]$F_trend = F_trend + return(pars) + }))} -#' @title Compute the steady state as a function of the egg deposition rate eta -#' @description This method dispatches on the type of `Lpar`. -#' @inheritParams xde_steady_state_L -#' @return none -#' @export -xde_steady_state_L.trivial = function(eta, Lpar){ - return(numeric(0)) -} -#' @title **L** Component Derivatives for the `trivial` model -#' @description Return a numeric vector of length 0 -#' @inheritParams dLdt -#' @return an empty [list] +#' @title Setup Initial Values for the **L** Component `trivial` Module +#' @description The `trivial` module initial values are an empty list +#' @inheritParams setup_Linits +#' @return a [list] #' @export -dLdt.trivial <- function(t, y, pars, s) { - return(numeric(0)) +setup_Linits.trivial = function(pars, s, Lopts=list()){ + pars$Linits[[s]] = list() + return(pars) } -#' @title Return the variables as a list +#' @title List **L** Component Variables for `trivial` #' @description This method dispatches on the type of `pars$Lpar[[s]]` #' @inheritParams list_Lvars #' @return an empty [list] @@ -115,67 +134,49 @@ list_Lvars.trivial <- function(y, pars, s){ return(list()) } -#' @title Return **L** Component variables as a list -#' @description This method dispatches on the type of `pars$Lpar[[s]]` -#' @inheritParams put_Lvars -#' @return a [list] -#' @export -put_Lvars.trivial <- function(Lvars, y, pars, s){ - return(y) -} - -#' @title Derivatives for aquatic stage mosquitoes -#' @description Implements [Update_Lt] for the trivial (forced emergence) model. -#' @inheritParams Update_Lt -#' @return a [numeric] vector -#' @export -Update_Lt.trivial <- function(t, y, pars, s) { - return(list()) -} -#' @title Setup `Lpar` for the `trivial` module -#' @description Implements [make_Lpar] for the trivial model -#' @inheritParams make_Lpar -#' @return a [list] vector +#' @title Set the Initial Values for `trivial` (**L** Component) +#' @description Returns the unmodified **`xds`** object +#' @inheritParams set_Linits +#' @return an **`xds`** object #' @export -make_Lpar.trivial = function(Lname, pars, s, Lopts=list()){ - pars$Lpar[[s]] = create_Lpar_trivial(pars$nHabitats, Lopts) +set_Linits.trivial <- function(pars, s=1, Lopts=list()) { return(pars) } - -#' @title Setup Initial Values for the **L** Component `trivial` Module -#' @description The `trivial` module initial values are an empty list -#' @inheritParams make_Linits -#' @return a [list] +#' @title Update Initial Values for `basicL` from a state vector `y` +#' @description Returns the unmodified **`xds`** object +#' @inheritParams update_Linits +#' @return an **`xds`** object #' @export -make_Linits.trivial = function(pars, s, Lopts=list()){ - pars$Linits[[s]] = list() +update_Linits.trivial<- function(pars, y, s) { return(pars) } -#' @title Add indices for aquatic stage mosquitoes to parameter list -#' @description Implements [make_indices_L] for trivial (forced emergence) model. -#' @inheritParams make_indices_L -#' @return none +#' @title Setup Variable Indices for `trivial` (**L** Component) +#' @description Implements [setup_indices_L] for trivial (forced emergence) model. +#' @inheritParams setup_indices_L +#' @return an **`xds`** object #' @export -make_indices_L.trivial <- function(pars, s) { +setup_indices_L.trivial <- function(pars, s) { return(pars) } -#' @title Update inits for the basic aquatic mosquito competition model -#' @inheritParams update_Linits +#' @title Parse **L** Component Variables for `basicL` +#' @description Return a numeric vector of length 0 +#' @inheritParams parse_Lorbits #' @return none #' @export -update_Linits.trivial<- function(pars, y, s) { - return(pars) +parse_Lorbits.trivial <- function(outputs, pars, s) { + return(numeric(0)) } -#' @title Parse the variable names for the trivial model -#' @description Implements [parse_Lorbits] for the trivial model. -#' @inheritParams parse_Lorbits -#' @return [list] +#' @title Compute the Steady State of `dLdt.trivial` (**L** Component) +#' @description Return a numeric vector of length 0 +#' @inheritParams xde_steady_state_L +#' @return none #' @export -parse_Lorbits.trivial <- function(outputs, pars, s) { +xde_steady_state_L.trivial = function(eta, Lpar){ return(numeric(0)) } + diff --git a/R/utils.R b/R/utils.R index 4ba08dc26..5a46d6ab7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -9,7 +9,7 @@ make_indices <- function(pars) { s = length(pars$Linits) if(s>0) for(ix in 1:s) - pars = make_indices_L(pars, ix) + pars = setup_indices_L(pars, ix) s = length(pars$MYZinits) if(s>0) diff --git a/R/xds_setup.R b/R/xds_setup.R index bf7ea1c76..0f513c5b2 100644 --- a/R/xds_setup.R +++ b/R/xds_setup.R @@ -103,8 +103,8 @@ xds_setup = function(xds = 'ode', # Aquatic Mosquito Dynamics pars$Lname <- Lname - pars <- make_Lpar(Lname, pars, 1, Lopts) - pars <- make_Linits(pars, 1, Lopts) + pars <- setup_Lpar(Lname, pars, 1, Lopts) + pars <- setup_Linits(pars, 1, Lopts) # Adult Mosquito Dynamics pars$MYZname <- MYZname @@ -206,8 +206,8 @@ xds_setup_mosy = function(xds = 'ode', # Aquatic Mosquito Dynamics pars$Lname <- Lname - pars <- make_Lpar(Lname, pars, 1, Lopts) - pars <- make_Linits(pars, 1, Lopts) + pars <- setup_Lpar(Lname, pars, 1, Lopts) + pars <- setup_Linits(pars, 1, Lopts) Xo <- list(kappa=kappa, HPop=HPop) pars <- make_Xpar("trivial", pars, 1, Xo) @@ -268,8 +268,8 @@ xds_setup_aquatic = function(xds = 'ode', # Aquatic Mosquito Dynamics pars$Lname <- Lname - pars <- make_Lpar(Lname, pars, 1, Lopts) - pars <- make_Linits(pars, 1, Lopts) + pars <- setup_Lpar(Lname, pars, 1, Lopts) + pars <- setup_Linits(pars, 1, Lopts) # Adult Mosquito Dynamics pars$MYZname <- "trivial" @@ -345,8 +345,8 @@ xds_setup_human = function(Xname = "SIS", class(pars$compute) <- 'na' # Aquatic Mosquito Dynamics - pars <- make_Lpar("trivial", pars, 1, list()) - pars <- make_Linits(pars, 1) + pars <- setup_Lpar("trivial", pars, 1, list()) + pars <- setup_Linits(pars, 1) # Mosquito Dynamics pars <- make_MYZpar("trivial", pars, 1, MYZopts) @@ -440,8 +440,8 @@ xds_setup_cohort = function(eir=1, pars <- set_eir(eir, pars) # Aquatic Mosquito Dynamics - pars <- make_Lpar("trivial", pars, 1, list()) - pars <- make_Linits(pars, 1) + pars <- setup_Lpar("trivial", pars, 1, list()) + pars <- setup_Linits(pars, 1) # Adult Mosquito Dynamics pars <- make_MYZpar("trivial", pars, 1, list()) diff --git a/_pkgdown.yml b/_pkgdown.yml index f63d9c30b..0c8273ce8 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -467,19 +467,19 @@ reference: contents: - dLdt - xde_steady_state_L - - make_Lpar + - setup_Lpar - Update_Lt - dts_steady_state_L - LBionomics - LBaseline - LBionomics.static - F_emerge - - make_Linits + - setup_Linits - list_Lvars - get_Lpars - set_Lpars - put_Lvars - - make_indices_L + - setup_indices_L - parse_Lorbits - get_Linits - set_Linits @@ -494,15 +494,15 @@ reference: - F_emerge.trivial - dLdt.trivial - Update_Lt.trivial - - make_Lpar.trivial - - create_Lpar_trivial - - make_Linits.trivial + - setup_Lpar.trivial + - make_Lpar_trivial + - setup_Linits.trivial - list_Lvars.trivial - get_Lpars.trivial - set_Lpars.trivial - set_Linits.trivial - put_Lvars.trivial - - make_indices_L.trivial + - setup_indices_L.trivial - parse_Lorbits.trivial - update_Linits.trivial - subtitle: basicL @@ -512,18 +512,18 @@ reference: - dLdt.basicL - Update_Lt.basicL - xde_steady_state_L.basicL - - make_Lpar.basicL - - create_Lpar_basicL + - setup_Lpar.basicL + - make_Lpar_basicL - LBionomics.basicL - LBaseline.basicL - F_emerge.basicL - - make_Linits.basicL - - create_Linits_basicL + - setup_Linits.basicL + - make_Linits_basicL - list_Lvars.basicL - get_Lpars.basicL - set_Lpars.basicL - set_Linits.basicL - - make_indices_L.basicL + - setup_indices_L.basicL - parse_Lorbits.basicL - update_Linits.basicL - title: Mosquito Bionomics diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 7fd13a453..1471ea94a 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -25,7 +25,7 @@ articles: Understanding_ramp.xds: Understanding_ramp.xds.html VectorControl: VectorControl.html Working: Working.html -last_built: 2024-10-03T00:40Z +last_built: 2024-10-03T22:32Z urls: reference: https://dd-harp.github.io/ramp.xds/reference article: https://dd-harp.github.io/ramp.xds/articles diff --git a/docs/reference/F_emerge.basicL.html b/docs/reference/F_emerge.basicL.html index 396bbe756..d105fce5b 100644 --- a/docs/reference/F_emerge.basicL.html +++ b/docs/reference/F_emerge.basicL.html @@ -1,5 +1,5 @@ -Compute emergent adults — F_emerge.basicL • ramp.xdsCompute Emergent adults — F_emerge.basicL • ramp.xdsCreate Lpar for basicL — create_Lpar_basicL • ramp.xdsBuild Lpar for basicL — create_Lpar_basicL • ramp.xds
diff --git a/docs/reference/dLdt.basicL.html b/docs/reference/dLdt.basicL.html index 592ab59c8..5e9ceb282 100644 --- a/docs/reference/dLdt.basicL.html +++ b/docs/reference/dLdt.basicL.html @@ -1,5 +1,5 @@ -L Component Derivatives for basicL — dLdt.basicL • ramp.xdsDerivatives for basicL (L Component) — dLdt.basicL • ramp.xds
diff --git a/docs/reference/index.html b/docs/reference/index.html index 39cc0bec0..955d296a1 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -237,7 +237,7 @@

Models – Aquatic Mosquito dLdt(<basicL>)

-

L Component Derivatives for basicL

+

Derivatives for basicL (L Component)

Interface

Functions that compute dynamical terms and exogenous variables

@@ -1573,7 +1573,7 @@

basicL <

dLdt(<basicL>)

-

L Component Derivatives for basicL

+

Derivatives for basicL (L Component)

Update_Lt(<basicL>)

@@ -1581,15 +1581,15 @@

basicL <

xde_steady_state_L(<basicL>)

-

Compute the Steady State for dLdt.basicL

+

Compute the Steady State for dLdt.basicL

make_Lpar(<basicL>)

-

Set up Lpar for the basicL model

+

Setup Lpar for basicL (L Component)

create_Lpar_basicL()

-

Create Lpar for basicL

+

Build Lpar for basicL

LBionomics(<basicL>)

@@ -1601,7 +1601,7 @@

basicL <

F_emerge(<basicL>)

-

Compute emergent adults

+

Compute Emergent adults

make_Linits(<basicL>)

diff --git a/docs/reference/make_Lpar.basicL.html b/docs/reference/make_Lpar.basicL.html index 73954cbc9..6577fc8a5 100644 --- a/docs/reference/make_Lpar.basicL.html +++ b/docs/reference/make_Lpar.basicL.html @@ -1,5 +1,5 @@ -Set up Lpar for the basicL model — make_Lpar.basicL • ramp.xdsSetup Lpar for basicL (L Component) — make_Lpar.basicL • ramp.xds