# NOT RUN {
# data preparation
data("florentine")
n <- network.size(flobusiness)
wealth <- get.vertex.attribute(flobusiness, "wealth")
priorates <- get.vertex.attribute(flobusiness, "priorates")
wealth.icov <- matrix(rep(wealth, n), ncol = n, byrow = TRUE)
priorates.icov <- matrix(rep(priorates, n), ncol = n, byrow = TRUE)
interac <- wealth.icov * priorates.icov
# estimate model with interaction effect
model <- ergm(flobusiness ~ edges + esp(1) + edgecov(wealth.icov)
+ edgecov(priorates.icov) + edgecov(interac))
# plot the interaction (note the additional optional ggplot2 elements)
marginalplot(model, var1 = "edgecov.wealth.icov",
var2 = "edgecov.priorates.icov", inter = "edgecov.interac",
color = "darkred", rug = TRUE, point = FALSE, xlab = "Priorates",
ylab = "Wealth") + theme_bw() + ggtitle("Interaction effect")
# }
Run the code above in your browser using DataLab