Learn R Programming

EpiModel (version 2.2.1)

trackers.net: Trackers: netsim Module

Description

This function apply the user provided epi trackers

Usage

trackers.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.

Optional Module

This module is not included by default

The <code>tracker.list</code> list

tracker.list is a list of NAMED functions stored in the control list of the dat master list object.

Tracker Functions

This module will apply the tracker functions present in the control list tracker.list. Each tracker must be a function with EXACTLY two arguments: the dat Master list object and at the current time step. They must return a VALUE of length one (numeric, logical or character).

See Also

netsim

Examples

Run this code
if (FALSE) {

# Create some trackers
epi_prop_infected <- function(dat, at) {
  needed_attributes <- c("status", "active")
  output <- with(get_attr_list(dat, needed_attributes), {
    pop <- active == 1
    cond <- status == "i"

    out <- sum(cond & pop, na.rm = TRUE) / sum(pop, na.rm = TRUE)

    out
  })

  return(output)
}

epi_s_num <- function(dat, at) {
  needed_attributes <- c("status")
  output <- with(get_attr_list(dat, needed_attributes), {
    out <- sum(status == "s", na.rm = TRUE)

    out
  })

  return(output)
}

# Create the `tracker.list` list
tracker.list <- list(
  prop_infected = epi_prop_infected,
  s_num         = epi_s_num
)

 param <- param.net(
   inf.prob = 0.3,
   act.rate = 0.5
 )

# Enable the module in `control` and add the `tracker.list` element
 control <- control.net(
   type = NULL, # must be NULL as we use a custom module
   nsims = 2,
   nsteps = 5,
   verbose = FALSE,
   infection.FUN = infection.net,
   trackers.FUN = trackers.net,
   tracker.list = tracker.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)

df <- as.data.frame(mod)

df

}

Run the code above in your browser using DataLab