0

I was wondering whether it is possible to simulate networks that come from an ERGM distribution in which the nodes have attributes. For example, if I wanted to simulate a network where triangles between nodes with similar attributes are more likely, I would do something like:

library(ergm)

g_sim = simulate(network(n, directed=FALSE) ~ triangles + nodematch, 
                 nsim=1, 
                 coef=thetas)

But the thing is that these kind of statistics that depend on node attributes (i.e. like nodematch) require parameters, which I don't have because the network doesn't exist beforehand (I'm trying to simulate it).

How could this be done?

Tendero
  • 1,136
  • 2
  • 19
  • 34

1 Answers1

0

Will something like this work?

library(ergm)

                                        # Initialize an empty network with N nodes
N <- 50
g <- network(1, directed = FALSE)
add.vertices(g, N - network.size(g))

                                        # Make up a node classification to go with nodematch
type <- rbinom(N, 1, .25)
g %v% "type" <- ifelse(type, "green", "blue")

                                        # Set the parameters of the model.
                                        # Use large coefficients to make the result clear.
                                        # These coefficients should set the base density and the
                                        # density of edges between nodes of the same type.
thetas <- c(-2.5, 2.5)

                                        # Simulate one network
                                        # I'm using edges instead of triangles because of the
                                        # tendancy towards degeneracy with triangles (my first attempt
                                        # had a density of 1.0)
g_sim <- simulate(
    g ~ edges + nodematch("type"), 
    nsim = 1, 
    coef = thetas
)

                                        # Plot to be sure. There should be many more edges between
                                        # nodes of the same color than nodes of different colors.
plot(g_sim, vertex.col = g %v% "type")

                                        # Are the coefficients similar to what they should be?
m <- ergm(g_sim ~ edges + nodematch("type"))
summary(m)
nmaclaren
  • 73
  • 6