Skip to contents

By default, a tool acts on every virus in the model. These functions restrict a tool (all four of its effects: susceptibility reduction, transmission reduction, recovery enhancer, and death reduction) to specific viruses, e.g., a vaccine that only protects against one disease.

Usage

add_target_tool(tool, virus)

set_targets_tool(tool, viruses)

get_targets_tool(tool)

clear_targets_tool(tool)

get_lineage_virus(virus)

Arguments

tool

An object of class epiworld_tool.

virus

An object of class epiworld_virus, a list of them, or an integer vector of virus lineage ids (see details). In get_lineage_virus(), a single epiworld_virus.

viruses

Same as virus. Use NULL (or an empty vector) to make the tool act on every virus again.

Value

  • add_target_tool(), set_targets_tool(), and clear_targets_tool() return the tool (invisibly).

  • get_targets_tool() returns an integer vector with the targeted lineage ids. An empty vector means the tool acts on every virus.

  • get_lineage_virus() returns the lineage id of the virus (an integer), or NA if the virus has not been added to a model yet.

Details

Tools target viruses by lineage. A lineage is a virus added to a model with add_virus() (or created by the model itself, as in ModelSIRCONN()) together with all of its mutations. The lineage id is the virus id assigned when the virus was added to the model, and every variant of the virus keeps it, so a tool targeting a virus also acts on its variants. Only lineages 0 to 62 can be targeted.

A virus only has a lineage id after it has been added to a model, so call add_virus() before passing the virus to add_target_tool() or set_targets_tool(). Viruses that the model creates itself can be retrieved with get_virus().

The model keeps its own copy of each tool, so set the targets before calling add_tool(), or modify the model's copy retrieved with get_tool().

Examples

# A model with two diseases: "Flu" (created by the model) and "Measles"
model <- ModelSIRCONN(
  name              = "Flu",
  n                 = 2000,
  prevalence        = 0.01,
  contact_rate      = 4,
  transmission_rate = 0.5,
  recovery_rate     = 0.2
)

measles <- virus(
  name           = "Measles",
  prevalence     = 20,
  as_proportion  = FALSE,
  prob_infecting = 0.5,
  recovery_rate  = 0.2
)

add_virus(model, measles) # Assigns the lineage id
get_lineage_virus(get_virus(model, 0)) # Flu: 0
#> [1] 0
get_lineage_virus(measles) # Measles: 1
#> [1] 1

# A vaccine that only protects against measles
mmr <- tool(
  name                     = "MMR",
  prevalence               = 0.5,
  as_proportion            = TRUE,
  susceptibility_reduction = 0.97,
  transmission_reduction   = 0,
  recovery_enhancer        = 0,
  death_reduction          = 0
)

add_target_tool(mmr, measles)
get_targets_tool(mmr)
#> [1] 1

add_tool(model, mmr)
run(model, ndays = 50, seed = 1912)
#> _________________________________________________________________________
#> |Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> |
summary(model)
#> ________________________________________________________________________________
#> ________________________________________________________________________________
#> SIMULATION STUDY
#> 
#> Name of the model   : Susceptible-Infected-Removed (SIR) (connected)
#> Population size     : 2000
#> Agents' data        : (none)
#> Number of entities  : 0
#> Days (duration)     : 50 (of 50)
#> Number of viruses   : 2
#> Last run elapsed t  : 1.00ms
#> Last run speed      : 56.72 million agents x day / second
#> Rewiring            : off
#> Last seed used      : 1912
#> 
#> Global events:
#>  - Update infected individuals (runs daily)
#> 
#> Virus(es):
#>  - Flu
#>  - Measles
#> 
#> Tool(s):
#>  - MMR
#> 
#> Model parameters:
#>  - Contact rate      : 4.0000
#>  - Recovery rate     : 0.2000
#>  - Transmission rate : 0.5000
#> 
#> Distribution of the population at time 50:
#>   - (0) Susceptible : 1960 -> 0
#>   - (1) Infected    :   40 -> 0
#>   - (2) Recovered   :    0 -> 2000
#> 
#> Transition Probabilities:
#>  - Susceptible  0.82  0.18     -
#>  - Infected        -  0.80  0.20
#>  - Recovered       -     -  1.00
#> 

# Targets can also be given as lineage ids
set_targets_tool(mmr, c(0, 1))
get_targets_tool(mmr)
#> [1] 0 1

# Back to acting on every virus
clear_targets_tool(mmr)
get_targets_tool(mmr)
#> integer(0)