Search code examples
rstatnet

In the ergm package in R, if I want to simulate graphs with homophily/clustering, what simulated network should I input in?


In the ergm and latentnet packages, they allow us to input a network and specify covariates. Then, we can add in effects like homophily and clustering (in the latentnet package). It seems there are two branches of applications here:

1) Have existing data/network, and want to see how it performs and how much homophily, clustering exists.

2) Do NOT have existing data, and want to generate from scratch a network that has enough homophily and clustering to our liking.

All of the examples in the above packages work with an existing dataset, samplike, which is the Sampson Monk Data. In the case that I am solely interested in generating a network with a given amount of homophily and clustering, what is the input network I should put in? For example, from code adapted:

library(ergm)
library(latentnet)
test.net = as.network(matrix(0,100,100), directed = F) #100-node network
test.net%v%"gender" = rbinom(100, size = 1, prob = 0.5) #nodal attribute
gest <- ergmm(test.net ~ euclidean(d=3,G=10) + nodematch("gender")
g.sim <- simulate(gest)
plot(g.sim, vertex.col = as.numeric(test.net%v%"gender"), vertex.cex = 2)

If I want to simulate out networks with clustering, should I start with a test.net object that already has 10 clusters (such as with a Stochastic Block Model)? Or should I start with just the 100 node network?


Solution

  • In ergm you would start with the 100 node network without edges. For example:

    library(ergm)
    
    test.net <- network(40, directed = FALSE, density = 0)
    test.net%v%"gender" = rbinom(40, size = 1, prob = 0.5)
    
    g.sim <- ergm::simulate(test.net ~ nodematch("gender") + edges,
             coef = c(2, -3)) #when using ergm::simulate with a formula as input,
                              #coefficients for ergm terms are required
    
    plot(g.sim, vertex.col = as.numeric(test.net%v%"gender"))
    

    Looking at the documentation for latentnet, it seems should function similarly, but I can't get it to generate a simulated network, either.