首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用R中的statnet向网络对象添加边属性

使用R中的statnet向网络对象添加边属性
EN

Stack Overflow用户
提问于 2016-10-29 09:36:33
回答 1查看 2K关注 0票数 1

我正在尝试使用函数add.edge.attribute()R中使用statnetnetwork对象添加边缘属性。

下面是network对象:

代码语言:javascript
复制
> 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,它的长度与网络中的边数相同:

代码语言:javascript
复制
> table(connections)
favorite  mention  retweet 
    2564     2041      705 
> sum(table(connections))
[1] 5310
> g <- set.edge.attribute(g, "connection_type", connections)

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

代码语言:javascript
复制
> 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()时,它似乎起作用了:

代码语言:javascript
复制
> tmp <- get.edge.attribute(g, "connection_type")
> str(tmp)
 chr [1:5310] "mention" "mention" "mention" "mention" "mention" "mention" "mention" "mention" ...

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

代码语言:javascript
复制
m1 <- ergm(g ~ edges + mutual + edgecov("connection_type"))
Error: There is no network attribute named connection_type

怎么回事?为什么没有显示边属性名称?为什么它似乎不能作为ergm模型的一部分?

EN

回答 1

Stack Overflow用户

发布于 2020-05-26 06:30:25

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40315212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档