if (FALSE) {
## Example 1: SI Model without Network Feedback
# Network model estimation
nw <- network_initialize(n = 100)
formation <- ~edges
target.stats <- 50
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 20)
est1 <- netest(nw, formation, target.stats, coef.diss, verbose = FALSE)
# Epidemic model
param <- param.net(inf.prob = 0.3)
init <- init.net(i.num = 10)
control <- control.net(type = "SI", nsteps = 100, nsims = 5, verbose.int = 0)
mod1 <- netsim(est1, param, init, control)
# Print, plot, and summarize the results
mod1
plot(mod1)
summary(mod1, at = 50)
## Example 2: SIR Model with Network Feedback (Two-Group)
nw <- network_initialize(n = 100)
nw <- set_vertex_attribute(nw, "group", rep(1:2, each = 50))
formation <- ~edges
target.stats <- 50
# Recalculate dissolution coefficient with departure rate
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 20,
d.rate = 0.0021)
# Reestimate the model with new coefficient
est2 <- netest(nw, formation, target.stats, coef.diss)
# Set parameters to include demographic rates
param <- param.net(inf.prob = 0.3, inf.prob.g2 = 0.15,
rec.rate = 0.02, rec.rate.g2 = 0.02,
a.rate = 0.002, a.rate.g2 = NA,
ds.rate = 0.001, ds.rate.g2 = 0.001,
di.rate = 0.001, di.rate.g2 = 0.001,
dr.rate = 0.001, dr.rate.g2 = 0.001)
init <- init.net(i.num = 10, i.num.g2 = 10,
r.num = 0, r.num.g2 = 0)
control <- control.net(type = "SIR", nsteps = 100, nsims = 5,
resimulate.network = TRUE, tergmLite = TRUE)
# Simulate the model with new network fit
mod2 <- netsim(est2, param, init, control)
# Print, plot, and summarize the results
mod2
plot(mod2)
summary(mod2, at = 40)
## Example 3: Post-Simulation Analysis
# Extract epi data as a data frame
as.data.frame(mod1)
as.data.frame(mod1, out = "mean")
# Extract the transmission matrix from simulation 1
get_transmat(mod1, sim = 1)
# Derive new epi statistics and plot them
mod1 <- mutate_epi(mod1, prev = i.num / num)
plot(mod1, y = "prev")
}
Run the code above in your browser using DataLab