簡體   English   中英

使用節點屬性模擬 ERGM

[英]Simulate ERGM with nodal attributes

我想知道是否有可能模擬來自 ERGM 分布的網絡,其中節點具有屬性。 例如,如果我想模擬 a.network ,其中具有相似屬性的節點之間的三角形更有可能出現,我會做類似的事情:

library(ergm)

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

但問題是,這些依賴於節點屬性(例如nodematch )的統計信息需要參數,我沒有這些參數,因為 .network 事先不存在(我正在嘗試模擬它)。

這怎么可能呢?

這樣的事情會奏效嗎?

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM