Sets the controls for stochastic network models simulated with
netsim.
control.net(
type,
nsteps,
start = 1,
nsims = 1,
ncores = 1,
resimulate.network = FALSE,
tergmLite = FALSE,
edges.correct.attr = NULL,
cumulative.edgelist = FALSE,
truncate.el.cuml = 0,
attr.rules,
epi.by,
initialize.FUN = initialize.net,
resim_nets.FUN = resim_nets,
summary_nets.FUN = summary_nets,
infection.FUN = NULL,
recovery.FUN = NULL,
departures.FUN = NULL,
arrivals.FUN = NULL,
nwupdate.FUN = nwupdate.net,
prevalence.FUN = prevalence.net,
verbose.FUN = verbose.net,
module.order = NULL,
save.nwstats = TRUE,
nwstats.formula = "formation",
save.transmat = TRUE,
save.network,
save.run = FALSE,
save.cumulative.edgelist = FALSE,
save.other,
verbose = TRUE,
verbose.int = 1,
skip.check = FALSE,
raw.output = FALSE,
future.use.plan = FALSE,
tergmLite.track.duration = FALSE,
set.control.ergm = control.simulate.formula(MCMC.burnin = 2e+05),
set.control.tergm = control.simulate.formula.tergm(MCMC.maxchanges =
.Machine$integer.max),
save.diss.stats = TRUE,
dat.updates = NULL,
...
)An EpiModel object of class control.net.
Disease type to be modeled, with the choice of "SI" for Susceptible-Infected
diseases, "SIR" for Susceptible-Infected-Recovered diseases, and "SIS" for
Susceptible-Infected-Susceptible diseases.
Number of time steps to simulate the model over. This must be a positive integer
that is equal to the final step of a simulation. If a simulation is restarted with start
argument, this number must be at least one greater than that argument's value.
For models with network resimulation, time point to start up the simulation. For
restarted simulations, this must be one greater than the final time step in the prior
simulation and must be less than the value in nsteps.
The total number of disease simulations.
Number of processor cores to run multiple simulations on, using
the future framework with multisession. See future.use.plan for
other future backends.
If TRUE, resimulate the network at each time step. This is required
when the epidemic or demographic processes impact the network structure (e.g., vital
dynamics). This parameter controls whether resim_nets.FUN performs actual network
resimulation; it does not affect the order in which modules are executed (see
module.order). Setting tergmLite = TRUE forces resimulate.network = TRUE with a
warning.
Logical indicating usage of either tergm (tergmLite = FALSE), or tergmLite
(tergmLite = TRUE). Default of FALSE. When TRUE, resimulate.network is
automatically set to TRUE (with a warning if the user explicitly set it to FALSE).
Name of a binary nodal attribute marking the nodes
eligible to form ties, used by edges_correct when it rescales the
edges coefficient to preserve mean degree as the population changes.
NULL by default, which counts every active node and is correct
whenever every active node can form a tie. Set it when the model
carries a subpopulation that stays active but is structurally
excluded from the network, such as an age band past a sexual-cessation
age whose target statistics are all zero. Without it the correction
counts nodes that can never hold an edge, and the whole of the
adjustment lands on the nodes that can, thinning mean degree among
them by the excluded share. Nodes with a value of 1 are eligible;
NA is treated as ineligible.
If TRUE, EpiModel maintains a running record
of every edge across the simulation (the cumulative edgelist) by
calling update_cumulative_edgelist once per network from the
built-in network-resimulation module (resim_nets) at every
time step. Off by default. Enabling it is the canonical way to
query partnership histories under tergmLite = TRUE, where the
full networkDynamic history is not retained. Inside a custom
module the live data is read via get_cumulative_edgelist or
get_cumulative_edgelists_df, and derived helpers
get_partners, get_cumulative_degree, get_forward_reachable,
and get_backward_reachable. See the
vignette("network-objects", package = "EpiModel") for a worked
example.
Number of time steps of the cumulative edgelist to
retain, passed as the truncate argument to each automatic
update_cumulative_edgelist call. Default is 0, which keeps
only currently active edges; use Inf to retain the full history
(memory permitting) or a positive integer to keep dissolved edges
for that many steps after they ended. Only relevant when
cumulative.edgelist = TRUE.
A list containing the rules for setting the attributes of incoming nodes, with one list element per attribute to be set (see details below).
A character vector of length 1 containing a nodal attribute for which subgroup stratified prevalence summary statistics are calculated. This nodal attribute must be contained in the network model formation formula, otherwise it is ignored.
Module to initialize the model at time 1, with the default function of
initialize.net.
Module to resimulate the network at each time step, with the default
function of resim_nets.
Module to extract summary statistics of the network
at each time step, with the default function of summary_nets.
Module to simulate disease infection, with the default function of
infection.net.
Module to simulate disease recovery, with the default function of
recovery.net.
Module to simulate departure or exit, with the default function of
departures.net.
Module to simulate arrivals or entries, with the default function of
arrivals.net.
Module to handle updating of network structure and nodal attributes due to
exogenous epidemic model processes, with the default function of nwupdate.net.
Module to calculate disease prevalence at each time step, with the default
function of prevalence.net.
Module to print simulation progress to screen, with the default function of
verbose.net.
A character vector of module names that lists modules in the order in which
they should be evaluated within each time step. If NULL, the modules will be evaluated
as follows: first any new modules supplied through ... in the order in which they are
listed, then the built-in modules in the order in which they are listed as arguments
above. initialize.FUN will always be run first and verbose.FUN will always be run last.
Module ordering is independent of resimulate.network: the specified order is always
respected regardless of whether network resimulation is enabled. In the default ordering,
resim_nets.FUN runs before infection.FUN, so the network is resimulated before
transmission is evaluated at each time step.
Important: when set, module.order replaces the entire dispatch order:
built-in modules not listed will not run. control.net() validates the entries
at construction time: each name must correspond to a .FUN argument that has
been supplied (either as a formal argument or through ...), and
initialize.FUN / verbose.FUN may not appear because they run outside the
per-step module loop. Omitting resim_nets.FUN, summary_nets.FUN, or
nwupdate.FUN produces a warning, since these built-ins are typically required
for correct semantics: resim_nets.FUN advances the TERGM each step,
summary_nets.FUN records network statistics, and nwupdate.FUN applies
vertex (de)activation from active/exitTime/entrTime and copies nodal
attributes to the network.
If TRUE, save network statistics in a data frame. The statistics to be
saved are specified in the nwstats.formula argument.
A right-hand sided ERGM formula that includes network statistics of
interest, with the default to the formation formula terms. Supports multilayer
specification.
If TRUE, complete transmission matrix is saved at simulation end.
If TRUE, networkDynamic or networkLite object is saved at simulation end.
If TRUE, the run sublist of dat is saved, allowing a
simulation to restart from this output.
If TRUE, the cumulative edgelist is
attached to the returned netsim object as
sim$cumulative.edgelist, a list with one element per simulation
(the same data.frame shape produced by
get_cumulative_edgelists_df). Requires cumulative.edgelist = TRUE; without it, no history is collected to save. Off by default
to keep output objects small.
A character vector of elements on the netsim_dat main data list to save out
after each simulation. One example for base models is the attribute list, "attr", at
the final time step.
If TRUE, print model progress to the console.
Time step interval for printing progress to console, where 0 prints
completion status of entire simulation and positive integer x prints progress after
every x time steps. The default is to print progress after each time step.
If TRUE, skips the default error checking for the structure and consistency
of the parameter values, initial conditions, and control settings before running base
epidemic models. Setting this to FALSE is recommended when running models with new
modules specified.
If TRUE, netsim will output a list of raw data (one per simulation) instead
of a cleaned and formatted netsim object.
If FALSE, netsim uses multisession with workers = ncores for its
parallelization. If TRUE, netsim uses the user-defined plan from globalEnv. It may also be
given the output of a future::tweak() call, which sets up a user-defined temporary plan within
netsim; this can be useful for distributed computation (HPC).
If TRUE, track duration information for models in tergmLite
simulations. Supports multilayer specification.
Control arguments passed to ergm::simulate_formula.network. In netsim,
this is only used when initializing the network with edapprox = TRUE. All other
simulations in netsim use tergm. Supports multilayer specification.
Control arguments passed to tergm::simulate_formula.network. See the
help file for netdx for details and examples on specifying this parameter. Supports
multilayer specification.
If TRUE, netsim will compute and save duration and dissolution
statistics for plotting and printing, provided save.network is TRUE, tergmLite is
FALSE, and the dissolution model is homogeneous.
Either NULL, a single function taking arguments dat,
at, and network, or a list of functions of length one greater
than the number of networks being simulated, with each function in
the list taking arguments dat and at. Here dat is the main
netsim_dat class object, at is the current timestep, and network
is an index indicating the current position within the sequence of
network (re)simulations on each time step. If a single function is
passed, it will be called before the first network is simulated and
after each network is simulated, with network = 0L before the first
network is simulated and with network = i after the ith network
is simulated. If a list of functions is passed, the first function
will be called before the first network is simulated, and the
i + 1th function will be called after the ith network is
simulated. (Note that at = 0L is used for initial cross-sectional
simulations in sim_nets_t1.) The function(s) should return the
netsim_dat object with any updates needed to correctly represent the
network states for calls to simulate and/or summary. This can be
useful if nodal attributes appearing in one network model depend on
nodal degrees in a different network.
Additional control settings passed to model.
The attr.rules parameter is used to specify the rules for how nodal attribute values for
incoming nodes should be set. These rules are only necessary for models in which there are
incoming nodes (i.e., arrivals). There are three rules available for each attribute value:
current: new nodes will be assigned this attribute in proportion to the distribution of
that attribute among existing nodes at that current time step.
t1: new nodes will be assigned this attribute in proportion to the distribution of that
attribute among nodes at time 1 (that is, the proportions set in the original network for
netest).
Value: all new nodes will be assigned this specific value, with no variation.
For example, the rules list attr.rules = list(race = "t1", sex = "current", status = "s")
specifies how the race, sex, and status attributes should be set for incoming nodes. By default,
the rule is "current" for all attributes except status, in which case it is "s" (that is, all
incoming nodes are susceptible).
netsim has a built-in checkpoint system to prevent losing computation work if the function is
interrupted (SIGINT, power loss, time limit exceeded on a computation cluster). When enabled,
each simulation will be saved every .checkpoint.steps time steps. Then, if a checkpoint enabled
simulation is launched again with netsim, it will restart at the last checkpoint available in
the saved data.
To enable the checkpoint capabilities of netsim, two control arguments have to be set:
.checkpoint.steps, which is a positive number of time steps to be run between each file save;
and .checkpoint.dir, which is the path to a directory to save the checkpointed data. If
.checkpoint.dir directory does not exist, netsim will attempt to create it on the first
checkpoint save. With these two controls defined, one can simply re-run netsim with the same
arguments to restart a set of simulations that were interrupted.
Simulations are checkpointed individually: for example, if 3 simulations are run on a single core,
the first 2 are finished, then the interruption occurs during the third, netsim will only
restart the third one from the last checkpoint.
A .checkpoint.compress argument can be set to overwrite the compress argument in saveRDS
used to save the checkpointed data. The current default for saveRDS is gunzip (gz), which
provides fast compression that usually works well on netsim objects.
By default, if netsim reaches the end of all simulations, the checkpoint data directory and its
content are removed before returning the netsim object. The .checkpoint.keep argument can be
set to TRUE to prevent this removal to inspect the raw simulation objects.
Base network models use a set of module functions that specify how the individual nodes in the
network are subjected to infection, recovery, demographics, and other processes. Core modules are
those listed in the .FUN arguments. For each module, there is a default function used in
the simulation. The default infection module, for example, is contained in the infection.net
function.
For original models, one may substitute replacement module functions for any of the default
functions. New modules may be added to the workflow at each time step by passing a module function
via the ... argument. Consult the
Extending EpiModel
section of the Network Modeling for Epidemics course materials.
One may remove existing modules, such as arrivals.FUN, from the workflow by setting
the parameter value for that argument to NULL.
netsim implements an "End Horizon" mechanism, where a set of modules are
removed from the simulation at a specific time step. This is enabled through
the end.horizon parameter to control.net.
This parameter must receive a list with fields at, the time step at which
the end horizon occurs, and modules, a character vector with the names of
the modules to remove. For example, list(at = 208, modules = c("arrivals.FUN", "infections.FUN")).
control.net sets the required control settings for any network model solved with the netsim
function. Controls are required for both base model types and when passing original process
modules. For an overview of control settings for base models, consult the
Network Modeling for Epidemics course materials For
all base models, the type argument is a necessary parameter and it has no default.
Use param.net to specify model parameters and init.net to specify the initial conditions.
Run the parameterized model with netsim.