【问题标题】:Simulate ERGM with nodal attributes用节点属性模拟 ERGM
【发布时间】:2023-01-02 02:53:06
【问题描述】:

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

library(ergm)

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

但问题是这些依赖于节点属性的统计数据(即像nodematch)需要参数,我没有参数,因为网络事先不存在(我正在尝试模拟它)。

这怎么可能呢?

【问题讨论】:

    标签: r graph simulation statnet


    【解决方案1】:

    这样的事情行得通吗?

    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)
    

    【讨论】:

      猜你喜欢
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      • 2016-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多