1

我正在尝试使用函数向对象添加network边缘属性。statnetRadd.edge.attribute()

这是network对象:

> g
 Network attributes:
  vertices = 866 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = TRUE 
  bipartite = FALSE 
  total edges= 5310 
    missing edges= 0 
    non-missing edges= 5310 

 Vertex attribute names: 
    vertex.names 

 Edge attribute names not shown

然后我使用add.edge.attribute(), 和下面的connections,它的长度与网络中的边数相同:

> table(connections)
favorite  mention  retweet 
    2564     2041      705 
> sum(table(connections))
[1] 5310
> g <- set.edge.attribute(g, "connection_type", connections)

但是,当我检查network对象时,似乎没有任何改变:

> g
 Network attributes:
  vertices = 866 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = TRUE 
  bipartite = FALSE 
  total edges= 5310 
    missing edges= 0 
    non-missing edges= 5310 

 Vertex attribute names: 
    membership vertex.names 

 Edge attribute names not shown

然而,当我检查时get.edge.attribute(),它似乎奏效了:

> tmp <- get.edge.attribute(g, "connection_type")
> str(tmp)
 chr [1:5310] "mention" "mention" "mention" "mention" "mention" "mention" "mention" "mention" ...

而且,当我尝试将 edge 属性用作ergm模型的一部分时 - 我尝试使用edgecov(),返回以下错误:

m1 <- ergm(g ~ edges + mutual + edgecov("connection_type"))
Error: There is no network attribute named connection_type

是什么赋予了?为什么没有显示边缘属性名称?为什么它似乎不能作为 ergm 模型的一部分?

4

1 回答 1

-1

m1 <- ergm(g ~ 边 + 相互 + edgecov(g,"connection_type"))

于 2020-05-25T22:30:24.673 回答