
Last chance! 50% off unlimited learning
Sale ends in
Plots epidemiological and network data from a stochastic network
model simulated with netsim
.
# S3 method for 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,
qnts.smooth = TRUE,
legend,
leg.cex = 0.8,
axs = "r",
grid = FALSE,
add = FALSE,
network = 1,
at = 1,
col.status = FALSE,
shp.bip = NULL,
stats,
targ.line = TRUE,
targ.col,
targ.lwd = 2,
targ.lty = 2,
plots.joined,
...
)
An EpiModel
model object of class netsim
.
Type of plot: "epi"
for epidemic model results,
"network"
for a static network plot (plot.network
),
or "formation"
for network formation statistics.
Output compartments or flows from netsim
object to plot.
If TRUE
, plot prevalence of values rather than numbers
(see details).
If TRUE
, plot individual simulation lines. Default is
to plot lines for one-group models but not for two-group models.
If type="epi"
or "formation"
, a vector of
simulation numbers to plot. If type="network"
, a single
simulation number for network plot, or else "min"
to plot the
simulation number with the lowest disease prevalence, "max"
for
the simulation with the highest disease prevalence, or "mean"
for the simulation with the prevalance closest to the mean across
simulations at the specified time step.
Vector of any standard R color format for simulation lines.
Line width for simulation lines.
Transparency level for simulation lines, where 0 = transparent
and 1 = opaque (see transco
).
If TRUE
, plot mean of simulations across time.
If TRUE
, use a lowess smoother on the mean line.
Vector of any standard R color format for mean lines.
Line width for mean lines.
Line type for mean lines.
If numeric, plot polygon of simulation quantiles based on the
range implied by the argument (see details). If FALSE
, suppress
polygon from plot.
Vector of any standard R color format for polygons.
Transparency level for quantile polygons, where 0 =
transparent and 1 = opaque (see transco
).
If TRUE
, use a lowess smoother on quantile polygons.
If TRUE
, plot default legend.
Legend scale size.
Plot axis type (see par
for details), with default
to "r"
.
If TRUE
, a grid is added to the background of plot
(see grid
for details), with default of nx by ny.
If TRUE
, new plot window is not called and lines are added to
existing plot window.
Network number, for simulations with multiple networks representing the population.
If type="network"
, time step for network graph.
If TRUE
and type="network"
, automatic disease
status colors (blue = susceptible, red = infected, green = recovered).
If type="network"
and a bipartite simulation, shapes
for the mode 2 vertices, with acceptable inputs of "triangle" and
"square". Mode 1 vertices will be circles.
If type="formation"
, network statistics to plot, among
those specified in nwstats.formula
of control.net
,
with the default to plot all statistics.
If TRUE
, plot target or expected value line for
the statistic of interest.
Vector of standard R colors for target statistic lines, with
default colors based on RColorBrewer
color palettes.
Line width for the line showing the target statistic values.
Line type for the line showing the target statistic values.
If TRUE
and type="formation"
, combine all
target statistics in one plot, versus one plot per target statistic if
FALSE
.
additional arguments to pass.
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 the plot.network
function in the
network
package. Consult the help page for plot.network
for all of the plotting parameters. In addition, four plotting parameters
specific to netsim
plots are available: sim
, at
,
col.status
, and shp.bip
.
type="formation"
: summary network statistics related to
the network model formation are plotted. These plots are similar to the
formation plots for netdx
objects. When running a netsim
simulation, one must specify there that save.nwstats=TRUE
; the
plot here will then show the network statistics requested explicitly in
nwstats.formula
, or will use the formation formula set in
netest
otherwise.
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
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% of the data. This is specified by qnts=0.5
. To show the
middle 95% of the data, specify qnts=0.95
. To toggle off the polygons
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 aide 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.
# NOT RUN {
## Independent SI Model
# Initialize network and set network model parameters
nw <- network.initialize(n = 100, bipartite = 50, directed = FALSE)
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.m2 = 0.15)
init <- init.net(i.num = 10, i.num.m2 = 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")
# 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")
plot(mod, type = "network", main = "Max Prev | Time 50",
col.status = TRUE, at = 20, sims = "max")
# Automatic shape by mode number (circle = mode 1)
par(mar = c(0,0,0,0))
plot(mod, type = "network", at = 20, col.status = TRUE, shp.bip = "square")
plot(mod, type = "network", at = 20, col.status = TRUE, shp.bip = "triangle")
# 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")
# }
Run the code above in your browser using DataLab