I am trying to simulate a network using ergm (specifics below) that has nodematch, but would like it not to have isolates. Specifically, I want it to be fully connected; I don't want to remove isolates, but rather create a network that doesn't have any to begin with.
I know that the ergm package has an *isolates *term that dictates the number of isolates that are in the network; however, I'm unsure of how to implement it. Adding 0 as the coefficient for the *isolates *term doesn't work, as I kind of expected.
N <- 100
nett <- network(N, directed=TRUE, density=0)
nett <- set_vertex_attribute(nett, "wearable", rep(c("Y","N"), times=c(N*0.21, N*0.79)))
nt.sim <- simulate(nett ~ edges + nodematch("wearable") + isolates, coef=c(qlogis(0.05),qlogis(0.1), 0))
plot(nt.sim, vertex.col=nodeColors)
You're almost there. The isolates
coef has to be - Inf
to prevent isolates. Setting it to 0 essentially has no effect (as if the term was absent). Here is your code edited with set.seed
added and you can use name of the vertex attribute with vertex.col
to have the nodes colored by that attribute:
library(ergm)
set.seed(666)
N <- 100
nett <- network(N, directed=TRUE, density=0)
nett <- set.vertex.attribute(nett, "wearable",
rep(c("Y","N"), times=c(N*0.21, N*0.79)))
nt.sim <- simulate(
nett ~ edges + nodematch("wearable") + isolates,
coef=c(qlogis(0.05),qlogis(0.1), - Inf)
)
plot(nt.sim, vertex.col="wearable")