在R

时间:2016-10-29 01:36:33

标签: r statnet

我正在尝试使用函数networkstatnet中使用Radd.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模型的一部分工作?

1 个答案:

答案 0 :(得分:-1)

m1 <-ergm(g〜边+相互+ edgecov(g,“ connection_type”))