if (FALSE) {
# Network initialization and model parameterization
nw <- network_initialize(n = 500)
nw <- set_vertex_attribute(nw, "sex", rbinom(500, 1, 0.5))
formation <- ~edges + nodematch("sex")
target.stats <- c(500, 300)
coef.diss <- dissolution_coefs(dissolution = ~offset(edges) +
offset(nodematch("sex")), duration = c(50, 40))
# Estimate the model
est <- netest(nw, formation, target.stats, coef.diss, verbose = FALSE)
# Static diagnostics
dx1 <- netdx(est, nsims = 1e4, dynamic = FALSE,
nwstats.formula = ~edges + meandeg + concurrent +
nodefactor("sex", levels = NULL) +
nodematch("sex"))
dx1
# Plot diagnostics
plot(dx1)
plot(dx1, stats = c("edges", "concurrent"), mean.col = "black",
sim.lines = TRUE, plots.joined = FALSE)
plot(dx1, stats = "edges", method = "b",
col = "seagreen3", grid = TRUE)
# Dynamic diagnostics
dx2 <- netdx(est, nsims = 10, nsteps = 500,
nwstats.formula = ~edges + meandeg + concurrent +
nodefactor("sex", levels = NULL) +
nodematch("sex"))
dx2
# Formation statistics plots, joined and separate
plot(dx2, grid = TRUE)
plot(dx2, type = "formation", plots.joined = TRUE)
plot(dx2, type = "formation", sims = 1, plots.joined = TRUE,
qnts = FALSE, sim.lines = TRUE, mean.line = FALSE)
plot(dx2, type = "formation", plots.joined = FALSE,
stats = c("edges", "concurrent"), grid = TRUE)
plot(dx2, method = "b", col = "bisque", grid = TRUE)
plot(dx2, method = "b", stats = "meandeg", col = "dodgerblue")
# Duration statistics plot
par(mfrow = c(1, 2))
# With duration imputed
plot(dx2, type = "duration", sim.line = TRUE, sim.lwd = 0.3,
targ.lty = 1, targ.lwd = 0.5)
# Without duration imputed
plot(dx2, type = "duration", sim.line = TRUE, sim.lwd = 0.3,
targ.lty = 1, targ.lwd = 0.5, duration.imputed = FALSE)
# Dissolution statistics plot
plot(dx2, type = "dissolution", qnts = 0.25, grid = TRUE)
plot(dx2, type = "dissolution", method = "b", col = "pink1")
}
Run the code above in your browser using DataLab