Learn R Programming

EpiModel (version 2.2.1)

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

Description

Module to modify the controls or parameters during the simulation

Usage

updater.net(dat, at)

Value

The updated dat Master list object.

Arguments

dat

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

at

Current time step.

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. Similarily, if a list control.updater.list is present in the controls, 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 or control named list with the names being the same as the parameter / control 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
if (FALSE) {

# 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
 )

# Create the control.updater.list
# these updaters will toggle on and off the verbosity of the model
control.updater.list <- list(
  list(
    at = 50,
    verbose = TRUE,
    control = list(
      verbose = TRUE
    )
  ),
  # this is another updater
  list(
    at = 75,
    verbose = TRUE,
    control = list(
      verbose = FALSE
    )
  )
)

# Enable the module in control, and add `control.updater.list` to it
 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,
   control.updater.list = control.updater.list
 )

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)

}

Run the code above in your browser using DataLab