使用节点属性模拟ERGM

ntjbwcob  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(119)

我想知道是否有可能模拟来自ERGM分布的网络,其中节点具有属性,例如,如果我想模拟一个网络,其中具有相似属性的节点之间的三角形更有可能,我会这样做:

library(ergm)

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

但问题是,这些依赖于节点属性的统计数据(如nodematch)需要参数,而我没有参数,因为网络事先并不存在(我试图模拟它)。
这怎么可能呢?

uxhixvfz

uxhixvfz1#

像这样的东西有用吗?

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)

相关问题