我正在尝试使用函数向对象添加network
边缘属性。statnet
R
add.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 模型的一部分?