Learn R Programming

EpiModel (version 2.5.0)

merge.netsim: Merge Model Simulations across netsim Objects

Description

Merges epidemiological data from two independent simulations of stochastic network models from netsim.

Usage

# S3 method for netsim
merge(
  x,
  y,
  keep.transmat = TRUE,
  keep.network = TRUE,
  keep.nwstats = TRUE,
  keep.other = TRUE,
  param.error = TRUE,
  keep.diss.stats = TRUE,
  ...
)

Value

An EpiModel object of class netsim containing the data from both x and y.

Arguments

x

An EpiModel object of class netsim.

y

Another EpiModel object of class netsim, with the identical model parameterization as x.

keep.transmat

If TRUE, keep the transmission matrices from the original x and y elements. Note: transmission matrices only saved when (save.transmat == TRUE).

keep.network

If TRUE, keep the networkDynamic objects from the original x and y elements. Note: network only saved when (tergmLite == FALSE).

keep.nwstats

If TRUE, keep the network statistics (as set by the nwstats.formula parameter in control.netsim) from the original x and y elements.

keep.other

If TRUE, keep the other simulation elements (as set by the save.other parameter in control.netsim) from the original x and y elements.

param.error

If TRUE, if x and y have different params (in param.net) or controls (passed in control.net) an error will prevent the merge. Use FALSE to override that check.

keep.diss.stats

If TRUE, keep diss.stats from the original x and y objects.

...

Additional merge arguments (not currently used).

Details

This merge function combines the results of two independent simulations of netsim class models, simulated under separate function calls. The model parameterization between the two calls must be exactly the same, except for the number of simulations in each call. This allows for manual parallelization of model simulations.

This merge function does not work the same as the default merge, which allows for a combined object where the structure differs between the input elements. Instead, the function checks that objects are identical in model parameterization in every respect (except number of simulations) and binds the results.

Examples

Run this code
# Network model
nw <- network_initialize(n = 100)
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 10)
est <- netest(nw, formation = ~edges, target.stats = 25,
              coef.diss = coef.diss, verbose = FALSE)

# Epidemic models
param <- param.net(inf.prob = 1)
init <- init.net(i.num = 1)
control <- control.net(type = "SI", nsteps = 20, nsims = 2,
                       save.nwstats = TRUE,
                       nwstats.formula = ~edges + degree(0),
                       verbose = FALSE)
x <- netsim(est, param, init, control)
y <- netsim(est, param, init, control)

# Merging
z <- merge(x, y)

# Examine separate and merged data
as.data.frame(x)
as.data.frame(y)
as.data.frame(z)

Run the code above in your browser using DataLab