# Initialize an empty network of 500 nodes divided equally into two races
nw <- network.initialize(n=500, directed=F)
nw <- set.vertex.attribute(nw, "race", value = rep(0:1, each=250))
# Set formation and dissolution formulas
formation <- ~ edges + nodematch("race") + degree(0) + concurrent
dissolution <- ~ offset(edges)
# Set target statistics for formation
target.stats <- c(225, 187, 180, 90)
# Set a vector of durations (here in months, but timestep units are arbitrary)
# Then use the dissolution.coefs functions to obtain the offset coefficients
durations <- 20
coef.diss <- dissolution.coefs(dissolution, durations)
coef.diss
# Set the stats.formula to include more degree tergms than the formation formula
dx.stats <- ~edges + nodematch("race") + degree(0:5)
# Estimate the STERGM with all the parameters set above with diagnostic
# simulations through 2000 timesteps, using the edges dissolution approximation
est <- epiNet.est(
nw,
formation,
dissolution,
target.stats,
coef.diss,
edapprox = TRUE,
stats.formula = dx.stats,
dx.end = 2000)
# Estimate the STERGM directly and use the default for model statistics
est2 <- epiNet.est(
nw,
formation,
dissolution,
target.stats,
coef.diss,
edapprox = FALSE)
est2
# Print and plot summaries
est
plot(est)
plot(est, type="duration")
Run the code above in your browser using DataLab