Learn R Programming

EpiModel (version 2.2.0)

updater.net: Module to modify the parameters during the simulation

Description

Module to modify the parameters during the simulation

Usage

updater.net(dat, at)

Arguments

dat

Master list object containing a networkDynamic object and other initialization information passed from netsim.

at

Current time step.

Value

The updated dat Master list object.

Details

If a list param.updater.list is present in the parameters, this module will update the param list with new values at given timesteps. An updater is a list containing an at element governing when the changes will happen, an optional verbose Boolean controlling whether to output a message when a change is made (default = TRUE) and a param named list with the names being the same as the parameter names and the new value to update with. If the new value is a function but the old one is not, the function will be applied to the current element (see example).

Examples

Run this code
# NOT RUN {
# Create the param.updater.list
param.updater.list <- list(
  # this is one updater
  list(
    at = 10,
    param = list(
      hiv.test.rate = rep(0.0128, 3),
      trans.scale = c(1.61, 0.836, 0.622)
    )
  ),
  # this is another updater
  list(
    at = 12,
    verbose = TRUE,
    param = list(
      hiv.test.rate = function(x) x * 3,
      trans.scale = function(x) x^2 / 3
    )
  )
)

 # Add it to params
 param <- param.net(
   inf.prob = 0.3,
   act.rate = 0.5,
   hiv.test.rate = rep(0.256, 3),
   trans.scale = c(1, 2, 3),
   param.updater.list = param.updater.list
 )

# Enable the module in control
 control <- control.net(
   type = NULL, # must be NULL as we use a custom module
   nsims = 1,
   nsteps = 20,
   verbose = FALSE,
   updater.FUN = updater.net,
   infection.FUN = infection.net
 )

nw <- network_initialize(n = 50)
nw <- set_vertex_attribute(nw, "race", rbinom(50, 1, 0.5))
est <- netest(
  nw,
  formation = ~edges,
  target.stats = 25,
  coef.diss = dissolution_coefs(~offset(edges), 10, 0),
  verbose = FALSE
)

init <- init.net(i.num = 10)
mod <- netsim(est, param, init, control)

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab