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