You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R中ergm.multi包运行多层ERGM时节点属性报错求助

多层ERGM模型运行报错:节点属性srh无效问题

报错信息

Error in ergm_Init_abort():! In term ‘nodeifactor’ in package ‘ergm’ (called from term ‘L’ in package ‘ergm.multi’): ‘srh’ is/are not valid nodal attribute(s).

问题背景

我使用R语言的ergm.multi包运行双层多层ERGM模型,单独为每层运行ERGM时完全正常,但运行多层模型时触发了上述节点属性错误。

多层网络构建过程

我按照statnet相关教程的方式构建多层网络,代码如下:

hf2_A <- network1 | network2 # 合并所有层的边集
# 设置边属性
hf2_A[,, names.eval="network1"] <- as.matrix(network1)
hf2_A[,, names.eval="network2"] <- as.matrix(network2)
hf2_A

hf_A <- Layer(hf2_A, c("network1","network2"))
hf_A

# 设置顶点属性
set.vertex.attribute(hf_A, attrname = "pid", value = as.vector(network_names_A))
set.vertex.attribute(hf_A,  attrname = "sup", value = as.vector(sup_A))
set.vertex.attribute(hf_A,  attrname = "nas", value = as.vector(nas_A))
set.vertex.attribute(hf_A,  attrname = "age", value = as.vector(age_A))
set.vertex.attribute(hf_A,  attrname = "srh", value = as.vector(srh_A))
set.vertex.attribute(hf_A,  attrname = "casmin", value = as.vector(casmin_A))

查看hf_A的网络信息,明确显示顶点属性包含srh:

Combined 2 networks on ‘.LayerID’/‘.LayerName’:
  1: n = 50, directed = TRUE, bipartite = FALSE, loops = FALSE
  2: n = 50, directed = TRUE, bipartite = FALSE, loops = FALSE

 Network attributes:
  vertices = 100 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  ergm:
            Length Class   Mode
constraints 2      formula call
  total edges= 247 
    missing edges= 0 
    non-missing edges= 247 

 Vertex attribute names: 
    .bipartite .LayerID .LayerName .undirected age casmin nas pid srh sup vertex.names 

 Edge attribute names: 
    network1 network2 

模型运行代码

但运行以下多层ERGM模型时,依然触发了相同的错误:

m1 <- ergm(hf_A ~ L(~edges + mutual + gwidegree(decay=.1, fixed=TRUE) + gwodegree(decay=.1, fixed=TRUE) + gwesp(decay=.1, fixed=TRUE)
                         +edgecov(A_friend_w1)+edgecov(A_kin_w1)
                         +nodeifactor("srh")+nodeofactor("srh")+nodeifactor("nas")+nodeofactor("nas")+nodematch("srh")+nodematch("nas")
                         +nodematch("age")+nodematch("casmin")+nodefactor("age")+nodefactor("casmin"), ~network1) 
              + L(~edges + mutual + gwidegree(decay=.1, fixed=TRUE) + gwodegree(decay=.1, fixed=TRUE) + gwesp(decay=.1, fixed=TRUE)
                         +edgecov(A_health_w1)+edgecov(A_kin_w1)
                         +nodeifactor("srh")+nodeofactor("srh")+nodeifactor("nas")+nodeofactor("nas")+nodematch("srh")+nodematch("nas")
                         +nodematch("age")+nodematch("casmin")+nodefactor("age")+nodefactor("casmin"), ~network2)
)

请问有人遇到过类似问题吗?或者知晓报错的具体原因?

内容的提问来源于stack exchange,提问作者Amelie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 18:45:58