plot.netsim {EpiModel} | R Documentation |
Plot Data from a Stochastic Network Epidemic Model
Description
Plots epidemiological and network data from a stochastic network
model simulated with netsim
.
Usage
## S3 method for class 'netsim'
plot(
x,
type = "epi",
y,
popfrac = FALSE,
sim.lines = FALSE,
sims,
sim.col,
sim.lwd,
sim.alpha,
mean.line = TRUE,
mean.smooth = TRUE,
mean.col,
mean.lwd = 2,
mean.lty = 1,
qnts = 0.5,
qnts.col,
qnts.alpha = 0.5,
qnts.smooth = TRUE,
legend,
leg.cex = 0.8,
axs = "r",
grid = FALSE,
add = FALSE,
network = 1,
at = 1,
col.status = FALSE,
shp.g2 = NULL,
vertex.cex,
stats,
targ.line = TRUE,
targ.col,
targ.lwd = 2,
targ.lty = 2,
plots.joined,
duration.imputed = TRUE,
method = "l",
...
)
Arguments
x |
An |
type |
Type of plot: |
y |
Output compartments or flows from |
popfrac |
If |
sim.lines |
If |
sims |
If |
sim.col |
Vector of any standard R color format for simulation lines. |
sim.lwd |
Line width for simulation lines. |
sim.alpha |
Transparency level for simulation lines, where
0 = transparent and 1 = opaque (see |
mean.line |
If |
mean.smooth |
If |
mean.col |
Vector of any standard R color format for mean lines. |
mean.lwd |
Line width for mean lines. |
mean.lty |
Line type for mean lines. |
qnts |
If numeric, plot polygon of simulation quantiles based on the
range implied by the argument (see details). If |
qnts.col |
Vector of any standard R color format for polygons. |
qnts.alpha |
Transparency level for quantile polygons, where 0 =
transparent and 1 = opaque (see |
qnts.smooth |
If |
legend |
If |
leg.cex |
Legend scale size. |
axs |
Plot axis type (see |
grid |
If |
add |
If |
network |
Network number, for simulations with multiple networks representing the population. |
at |
If |
col.status |
If |
shp.g2 |
If |
vertex.cex |
Relative size of plotted vertices if |
stats |
If |
targ.line |
If |
targ.col |
Vector of standard R colors for target statistic lines, with
default colors based on |
targ.lwd |
Line width for the line showing the target statistic values. |
targ.lty |
Line type for the line showing the target statistic values. |
plots.joined |
If |
duration.imputed |
If |
method |
Plot method for |
... |
Additional arguments to pass. |
Details
This plot function can produce three types of plots with a stochastic network
model simulated through netsim
:
-
type="epi"
: epidemic model results (e.g., disease prevalence and incidence) may be plotted. -
type="network"
: a static network plot will be generated. A static network plot of a dynamic network is a cross-sectional extraction of that dynamic network at a specific time point. This plotting function wraps theplot.network
function in thenetwork
package. Consult the help page forplot.network
for all of the plotting parameters. In addition, four plotting parameters specific tonetsim
plots are available:sim
,at
,col.status
, andshp.g2
. -
type="formation"
: summary network statistics related to the network model formation are plotted. These plots are similar to the formation plots fornetdx
objects. When running anetsim
simulation, one must specify there thatsave.nwstats=TRUE
; the plot here will then show the network statistics requested explicitly innwstats.formula
, or will use the formation formula set innetest
otherwise. -
type="duration","dissolution"
: as inplot.netdx
; supported inplot.netsim
only when the dissolution model is~offset(edges)
,tergmLite
isFALSE
, andsave.network
isTRUE
.
When type="epi"
, this plotting function will extract the
epidemiological output from a model object of class netsim
and plot
the time series data of disease prevalence and other results. The summary
statistics that the function calculates and plots are individual simulation
lines, means of the individual simulation lines, and quantiles of those
individual simulation lines. The mean line, toggled on with
mean.line=TRUE
, is calculated as the row mean across simulations at
each time step.
Compartment prevalences are the size of a compartment over some denominator.
To plot the raw numbers from any compartment, use popfrac=FALSE
; this
is the default for any plots of flows. The popfrac
parameter
calculates and plots the denominators of all specified compartments using
these rules: 1) for one-group models, the prevalence of any compartment is
the compartment size divided by the total population size; 2) for two-group
models, the prevalence of any compartment is the compartment size divided by
the group population size. For any prevalences that are not automatically
calculated, the mutate_epi
function may be used to add new
variables to the netsim
object to plot or analyze.
The quantiles show the range of outcome values within a certain specified
quantile range. By default, the interquartile range is shown: that is the
middle 50\
middle 95\
where they are plotted by default, specify qnts=FALSE
.
When type="network"
, this function will plot cross sections of the
simulated networks at specified time steps. Because it is only possible to
plot one time step from one simulation at a time, it is necessary to enter
these in the at
and sims
parameters. To aid in visualizing
representative and extreme simulations at specific time steps, the
sims
parameter may be set to "mean"
to plot the simulation in
which the disease prevalence is closest to the average across all
simulations, "min"
to plot the simulation in which the prevalence is
lowest, and "max"
to plot the simulation in which the prevalence is
highest.
See Also
Examples
## SI Model without Network Feedback
# Initialize network and set network model parameters
nw <- network_initialize(n = 100)
nw <- set_vertex_attribute(nw, "group", rep(1:2, each = 50))
formation <- ~edges
target.stats <- 50
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 20)
# Estimate the network model
est <- netest(nw, formation, target.stats, coef.diss, verbose = FALSE)
# Simulate the epidemic model
param <- param.net(inf.prob = 0.3, inf.prob.g2 = 0.15)
init <- init.net(i.num = 10, i.num.g2 = 10)
control <- control.net(type = "SI", nsteps = 20, nsims = 3,
verbose = FALSE, save.nwstats = TRUE,
nwstats.formula = ~edges + meandeg + concurrent)
mod <- netsim(est, param, init, control)
# Plot epidemic trajectory
plot(mod)
plot(mod, type = "epi", grid = TRUE)
plot(mod, type = "epi", popfrac = TRUE)
plot(mod, type = "epi", y = "si.flow", qnts = 1, ylim = c(0, 4))
# Plot static networks
par(mar = c(0, 0, 0, 0))
plot(mod, type = "network", vertex.cex = 1.5)
# Automatic coloring of infected nodes as red
par(mfrow = c(1, 2), mar = c(0, 0, 2, 0))
plot(mod, type = "network", main = "Min Prev | Time 50",
col.status = TRUE, at = 20, sims = "min", vertex.cex = 1.25)
plot(mod, type = "network", main = "Max Prev | Time 50",
col.status = TRUE, at = 20, sims = "max", vertex.cex = 1.25)
# Automatic shape by group number (circle = group 1)
par(mar = c(0, 0, 0, 0))
plot(mod, type = "network", at = 20, col.status = TRUE,
shp.g2 = "square")
plot(mod, type = "network", at = 20, col.status = TRUE,
shp.g2 = "triangle", vertex.cex = 2)
# Plot formation statistics
par(mfrow = c(1,1), mar = c(3,3,1,1), mgp = c(2,1,0))
plot(mod, type = "formation", grid = TRUE)
plot(mod, type = "formation", plots.joined = FALSE)
plot(mod, type = "formation", sims = 2:3)
plot(mod, type = "formation", plots.joined = FALSE,
stats = c("edges", "concurrent"))
plot(mod, type = "formation", stats = "meandeg",
mean.lwd = 1, qnts.col = "seagreen", mean.col = "black")