Title: | Framework for Tick Population and Infection Modeling |
---|---|
Description: | Code to specify, run, and then visualize and analyze the results of Ixodidae (hard-bodied ticks) population and infection dynamics models. Such models exist in the literature, but the source code to run them is not always available. 'IxPopDyMod' provides an easy way for these models to be written and shared. |
Authors: | Myles Stokowski [aut, cre], David Allen [aut] |
Maintainer: | Myles Stokowski <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0.9000 |
Built: | 2024-11-05 18:31:01 UTC |
Source: | https://github.com/dallenmidd/ixpopdymod |
Calculate annual growth rate
annual_growth_rate(out)
annual_growth_rate(out)
out |
Model output data frame |
Numeric vector of length one representing the annual factor by which the total tick population changes. To use this function, it is best to run the model for at least three years.
## Not run: out <- run(ogden2005) annual_growth_rate(out) ## End(Not run)
## Not run: out <- run(ogden2005) annual_growth_rate(out) ## End(Not run)
config
objectMake a config
object from the input parameters, and ensure that the inputs
meet the requirements for the model. The returned object is a complete
description of a model run scenario.
config( cycle, initial_population, preds = NULL, steps = 365L, max_duration = 365L, verbose = TRUE )
config( cycle, initial_population, preds = NULL, steps = 365L, max_duration = 365L, verbose = TRUE )
cycle |
A tick's |
initial_population |
Named numeric vector indicating starting population for each life stage. Life stages not specified are assumed to be 0. |
preds |
Optional input |
steps |
Numeric vector of length one indicating the duration to run the model over in days. |
max_duration |
Numeric vector of length one. Determines the maximum number of days that a duration-based transition can last, after which ticks are removed from the model/die. Default of 365 is likely sensible for most cases. |
verbose |
Boolean; whether to warn about coercion to inputs |
A config
object
# We build a simple example config my_config <- config( cycle = life_cycle( transition("a", "b", function() 0.1, "probability"), transition("b", "a", function() 10, "probability") ), initial_population = c(a = 1) ) # If we make a change to an existing `config`, it is a good idea to check # whether it is still valid by calling `config()` on it again. For example, # here we set the initial_population of a life stage that is not included in # the life cycle. my_config$initial_population <- c(a = 1, c = 1) ## Not run: # Now, we re-run the validations, which will throw an error do.call(config, my_config) ## End(Not run)
# We build a simple example config my_config <- config( cycle = life_cycle( transition("a", "b", function() 0.1, "probability"), transition("b", "a", function() 10, "probability") ), initial_population = c(a = 1) ) # If we make a change to an existing `config`, it is a good idea to check # whether it is still valid by calling `config()` on it again. For example, # here we set the initial_population of a life stage that is not included in # the life cycle. my_config$initial_population <- c(a = 1, c = 1) ## Not run: # Now, we re-run the validations, which will throw an error do.call(config, my_config) ## End(Not run)
This model configuration uses only non-delay transitions, and no transitions depend on predictors (e.g. weather or host community). Parameter values are selected so that the population is stable over time.
config_ex_1
config_ex_1
A config
This model configuration uses delay transitions for all transitions except
the adult to eggs transition. As in config_ex_1
, no transitions depend
on predictors, and the population is stable over time.
config_ex_2
config_ex_2
A config
Constant function
constant_fun(a)
constant_fun(a)
a |
Parameter |
Numeric vector of length 1 equal to input parameter a
constant_fun(1)
constant_fun(1)
Density dependent mortality
density_fun(x, y, a, b, c, pref)
density_fun(x, y, a, b, c, pref)
x |
Predictor 1 in transitions table. Numeric vector indicating host density for each of the host species. Length should be equal to the number of host species. |
y |
Predictor 2 in transitions table. Number of feeding ticks in life stages specified by predictor 2. |
a |
Parameter |
b |
Parameter |
c |
Parameter |
pref |
Parameters named |
Numeric vector of length 1, indicating mortality rate
density_fun(c(10, 20), 100, .1, .3, .2, c(.5, .8))
density_fun(c(10, 20), 100, .1, .3, .2, c(.5, .8))
Exponential function
expo_fun(x, a, b)
expo_fun(x, a, b)
x |
Predictor 1 in transitions table. |
a |
Parameter |
b |
Parameter |
Numeric vector of length 1
expo_fun(.5, .1, .3)
expo_fun(.5, .1, .3)
Probability of actively questing and then finding a host
feed_fun(x, y, a, pref, q, tmin, tmax)
feed_fun(x, y, a, pref, q, tmin, tmax)
x |
Predictor 1 in transitions table. Numeric vector indicating host density for each of the host species. Length should be equal to the number of host species. |
y |
Predictor 2 in transitions table. Numeric vector of length 1 indicating temperature. |
a |
Parameter |
pref |
Parameters named |
q |
Parameter |
tmin |
Parameter |
tmax |
Parameter |
Product of binomial and Briere functions (prob of finding a host) * (prob of active questing)
Numeric vector of length 1
feed_fun(10, 30, .001, .1, .5, 20, 40)
feed_fun(10, 30, .001, .1, .5, 20, 40)
Probability of finding a host and successfully feeding on it
find_n_feed(x, a, pref, feed_success)
find_n_feed(x, a, pref, feed_success)
x |
Predictor 1 in transitions table. Numeric vector indicating host density for each of the host species. Length should be equal to the number of host species. |
a |
Parameter |
pref |
Parameters named |
feed_success |
Parameters named |
Numeric vector of length 1 indicating probability that ticks find any host and then successfully feed on that host.
find_n_feed(10, .1, 1, .5) find_n_feed(runif(2) * 10, .1, runif(2), runif(2))
find_n_feed(10, .1, 1, .5) find_n_feed(runif(2) * 10, .1, runif(2), runif(2))
predictor_spec
Format a predictor_spec
## S3 method for class 'predictor_spec' format(x, ...)
## S3 method for class 'predictor_spec' format(x, ...)
x |
a predictor_spec |
... |
not used |
string representation of input
Get a predictor from input data
get_pred_from_table(time, pred, table)
get_pred_from_table(time, pred, table)
time |
Numeric vector of days to get data. Ignored if input is constant over time (as indicated by NA value in 'j_day' column) |
pred |
string specifying the name of the predictor, e.g. "host_den" |
table |
input predictors table |
a numeric vector of predictor values
Calculate multiplicative growth rate of population
growth_rate(out)
growth_rate(out)
out |
Model output data frame |
Numeric vector of length one representing daily growth rate.
out <- run(config_ex_1) growth_rate(out)
out <- run(config_ex_1) growth_rate(out)
Configuration for showing how we can modify host community data
host_example_config
host_example_config
A config
Configuration for showing infection dynamics
infect_example_config
infect_example_config
A config
Probability that a feeding tick becomes engorged infected or uninfected
infect_fun(x, from_infected, to_infected, host_rc, pref)
infect_fun(x, from_infected, to_infected, host_rc, pref)
x |
Predictor 1 in transitions table. Numeric vector indicating host density for each of the host species. Length should be equal to the number of host species. |
from_infected |
Parameter |
to_infected |
Parameter |
host_rc |
Parameters named |
pref |
Parameters named |
Since density dependent mortality is subtracted later, in this function we assume that all feeding ticks feed successfully and become engorged.
Numeric vector of length 1
infect_fun(10, 0, 0, .3, 1) infect_fun(10, 0, 1, .3, 1) infect_fun(10, 1, 1, .3, 1)
infect_fun(10, 0, 0, .3, 1) infect_fun(10, 0, 1, .3, 1) infect_fun(10, 1, 1, .3, 1)
life_cycle
from a collection of transition
sCreate a life_cycle
from a collection of transition
s
life_cycle(...)
life_cycle(...)
... |
A set of |
a life_cycle
Constructor for transition functions
new_transition_function(fun)
new_transition_function(fun)
fun |
A function Transition functions must return a numeric vector. See
|
Probability of actively questing times constant host finding probability
ogden_feed_fun(x, a, q, tmin, tmax)
ogden_feed_fun(x, a, q, tmin, tmax)
x |
Predictor 1 in transitions table. Numeric vector of length 1 indicating temperature. |
a |
Parameter |
q |
Parameter |
tmin |
Parameter |
tmax |
Parameter |
(const prob of finding a host) * (prob of active questing)
Numeric vector of length 1
Based on Ogden et al. (2005) doi:10.1016/j.ijpara.2004.12.013
ogden_feed_fun(30, .03, .01, 10, 35)
ogden_feed_fun(30, .03, .01, 10, 35)
This model configuration recreates the Ixodes scapularis (blacklegged tick) population dynamics model from Ogden et al. 2005. This is a relatively complete model of tick population dynamics, including the effects of both temperature and the host community on tick life-stage transitions. We include this configuration to show that our package can be used to recreate existing models.
ogden2005
ogden2005
A config
In this config, the population starts with 10000 questing adults. The predictor data includes average temperature for each day, and density of hosts over the model run. Here the host community is stable with 20 deer and 200 mice.
Ogden et al. (2005) doi:10.1016/j.ijpara.2004.12.013
data(ogden2005) ## Not run: output <- run(ogden2005) graph_population_each_group(output) ## End(Not run)
data(ogden2005) ## Not run: output <- run(ogden2005) graph_population_each_group(output) ## End(Not run)
Create a set of parameters
parameters(...)
parameters(...)
... |
A set of named numeric vectors, each corresponding to a parameter. If a parameter is of length > 1, each element must be named. |
a parameters
object
# create a set of scalar parameters parameters(a = 1, b = 2) # parameters of length > 1 may be useful for host-related parameters that # differ between host species, for example tick feeding success parameters(a = 1, feeding_success = c(deer = 0.49, squirrel = 0.17))
# create a set of scalar parameters parameters(a = 1, b = 2) # parameters of length > 1 may be useful for host-related parameters that # differ between host species, for example tick feeding success parameters(a = 1, feeding_success = c(deer = 0.49, squirrel = 0.17))
Specify how a single predictor should be used
predictor_spec(pred, first_day_only = TRUE)
predictor_spec(pred, first_day_only = TRUE)
pred |
String indicating where to get predictor data. Can be one of:
|
first_day_only |
Boolean indicating whether to repeat the predictor data
value from the first day of a |
a predictor_spec
list-based object
predictors
A data frame of input data to be used in as predictor values in transition functions.
predictors(df, verbose = FALSE)
predictors(df, verbose = FALSE)
df |
input data frame, with columns:
|
verbose |
Boolean; whether to warn about reordering the |
a predictors
object
predictor_spec
Print a predictor_spec
## S3 method for class 'predictor_spec' print(x, ...)
## S3 method for class 'predictor_spec' print(x, ...)
x |
a predictor_spec |
... |
not used |
Print a transition
## S3 method for class 'transition' print(x, ...)
## S3 method for class 'transition' print(x, ...)
x |
A |
... |
not used |
Run the model
run(cfg, progress = TRUE)
run(cfg, progress = TRUE)
cfg |
An |
progress |
Boolean indicating whether to log progress every 100 steps |
Data frame of population of ticks of each life stage each day
run(config_ex_1)
run(config_ex_1)
Mortality as a function of whether there is a snow on the ground
snow_cover_fun(x, no_snow_mort, snow_mort)
snow_cover_fun(x, no_snow_mort, snow_mort)
x |
amount of snow on ground |
no_snow_mort |
mortality with no snow on the ground |
snow_mort |
mortality with snow on the ground |
Configuration for showing how we can modify climate data
temp_example_config
temp_example_config
A config
transition
objectA transition
object represents a single transition between two tick life
stages, or the mortality rate from a life stage.
transition( from, to, fun, transition_type, mortality_type = NULL, predictors = NULL, parameters = list() )
transition( from, to, fun, transition_type, mortality_type = NULL, predictors = NULL, parameters = list() )
from |
The name of the life stage a tick is transitioning from. |
to |
The name of the life stage a tick is transitioning to, or NULL if the transition is representing mortality. |
fun |
The transition function to evaluate.
The inputs of the function are predictors and parameters. The output is
the daily probability of completing the transition, for |
transition_type |
One of:
|
mortality_type |
One of:
|
predictors |
Optional, a named list of |
parameters |
Optional, a |
a transition
object
This is a model configuration based on a literature search on the factors affect the winter tick life cycle. Many of the transitions and parameters in this configuration are drawn from Drew and Samuel (1986). We include this configuration to show that our package is flexible for modeling multiple tick species with different life histories.
winter_tick
winter_tick
An object of class config
of length 5.
Drew and Samuel (1986) doi:10.1139/z86-105
Drew and Samuel (1985) doi:10.7589/0090-3558-21.3.274
Addison and McLaughlin (1988) doi:10.2307/3282188
Ogden et al. (2005) doi:10.1016/j.ijpara.2004.12.013
data(winter_tick) ## Not run: output <- run(winter_tick) graph_population_each_group(winter_tick) ## End(Not run)
data(winter_tick) ## Not run: output <- run(winter_tick) graph_population_each_group(winter_tick) ## End(Not run)