virus {epiworldR}R Documentation

Virus design

Description

Viruses can be considered to be anything that can be transmitted (e.g., diseases, as well as ideas.) Most models in epiworldR can feature multiple viruses.

Usage

virus(
  name,
  prob_infecting,
  recovery_rate = 0.5,
  prob_death = 0,
  post_immunity = -1,
  incubation = 7
)

set_name_virus(virus, name)

get_name_virus(virus)

add_virus(model, virus, proportion)

add_virus_n(model, virus, n)

virus_set_state(virus, init, end, removed)

rm_virus(model, virus_pos)

virus_fun_logit(vars, coefs, model)

set_prob_infecting(virus, prob)

set_prob_infecting_ptr(virus, model, param)

set_prob_infecting_fun(virus, model, vfun)

set_prob_recovery(virus, prob)

set_prob_recovery_ptr(virus, model, param)

set_prob_recovery_fun(virus, model, vfun)

set_prob_death(virus, prob)

set_prob_death_ptr(virus, model, param)

set_prob_death_fun(virus, model, vfun)

set_incubation(virus, incubation)

set_incubation_ptr(virus, model, param)

set_incubation_fun(virus, model, vfun)

Arguments

name

of the virus

prob_infecting

Numeric scalar. Probability of infection (transmission).

recovery_rate

Numeric scalar. Probability of recovery.

prob_death

Numeric scalar. Probability of death.

post_immunity

Numeric scalar. Post immunity (prob of re-infection).

incubation

Numeric scalar. Incubation period (in days) of the virus.

virus

An object of class epiworld_virus

model

An object of class epiworld_model.

proportion

In the case of add_virus, a proportion, otherwise, an integer.

n

A positive integer. Initial count of agents to have the virus.

init, end, removed

states after acquiring a virus, removing a virus, and removing the agent as a result of the virus, respectively.

virus_pos

Positive integer. Index of the virus's position in the model.

vars

Integer vector. Indices (starting from 0) of the positions of the variables used to compute the logit probability.

coefs

Numeric vector. Of the same length of vars, is a vector of coefficients associated to the logit probability.

prob

Numeric scalar. A probability (between zero and one).

param

Character scalar. Name of the parameter featured in model that will be added to the virus (see details).

vfun

An object of class epiworld_virus_fun.

Details

The virus() function can be used to initialize a virus. Virus features can then be modified using the functions ⁠set_prob_*⁠.

The function virus_fun_logit() creates a "virus function" that can be evaluated for transmission, recovery, and death. As the name sugests, it computes those probabilities using a logit function (see examples).

The name of the epiworld_virus object can be manipulated with the functions set_name_virus() and get_name_virus().

In the case of set_prob_infecting_ptr, set_prob_recovery_ptr, and set_prob_death_ptr, the corresponding parameters is passed as a pointer to the virus. The implication of using pointers is that the values will be read directly from the model object, so changes will be reflected.

Value

Examples

mseirconn <- ModelSEIRCONN(
  name                = "COVID-19",
  prevalence          = 0.01, 
  n                   = 10000,
  contact_rate        = 4, 
  incubation_days     = 7, 
  transmission_rate   = 0.5,
  recovery_rate       = 0.99
)

delta <- virus("Delta Variant", 0, .5, .2, .01)

# Adding virus and setting/getting virus name
add_virus(mseirconn, delta, .3)
set_name_virus(delta, "COVID-19 Strain")
get_name_virus(delta)

run(mseirconn, ndays = 100, seed = 992)
mseirconn

rm_virus(mseirconn, 0) # Removing the first virus from the model object
add_virus_n(mseirconn, delta, 100) # Setting initial count of delta virus
                                   # to n = 100

# Setting parameters for the delta virus manually
set_prob_infecting(delta, 0.5)
set_prob_recovery(delta, 0.9)
set_prob_death(delta, 0.01)
run(mseirconn, ndays = 100, seed = 992) # Run the model to observe changes

# If the states were (for example):
# 1: Infected
# 2: Recovered
# 3: Dead
delta2 <- virus("Delta Variant 2", 0, .5, .2, .01)
virus_set_state(delta2, 1, 2, 3)
# Using the logit function --------------
sir <- ModelSIR(
  name = "COVID-19", prevalence = 0.01, 
  transmission_rate = 0.9, recovery = 0.1
  )

# Adding a small world population
agents_smallworld(
  sir,
  n = 10000,
  k = 5,
  d = FALSE,
  p = .01
)

run(sir, ndays = 50, seed = 11)
plot(sir)

# And adding features
dat <- cbind(
  female = sample.int(2, 10000, replace = TRUE) - 1,
  x      = rnorm(10000)
)

set_agents_data(sir, dat)

# Creating the logit function
vfun <- virus_fun_logit(
  vars  = c(0L, 1L),
  coefs = c(-1, 1),
  model = sir
)

# The infection prob is lower
hist(plogis(dat %*% rbind(-1,1)))

vfun # printing

set_prob_infecting_fun(
  virus = get_virus(sir, 0),
  model = sir,
  vfun  = vfun
  )
  
run(sir, ndays = 50, seed = 11)
plot(sir)



[Package epiworldR version 0.1-0 Index]