我有一个双模网络的边缘列表,类似于:
person  Event
Amy     football_game
Sam     picnic
Bob     art_show
我想在R中对此进行分析,但看起来我尝试的一切都失败了.将其转换为单模式网络会遇到内存限制,我无法弄清楚如何在igraph或tnet中将其分析为二分.
在igraph中,bipartite.projection给我所有FALSE,在使用的igraph对象上
net <- graph.edgelist(myobject)
在tnet上,我无法将igraph网转换为tnet网,当我尝试使用原始数据框时,它会因图中的重复而拒绝.
因此,以下任何一个的答案将非常感激:
bipartite.mapping功能?很抱歉,如果这些是基本问题,但文档很少.
例:
edgelist <- read.table(text="Person    Event
                             Amy       football
                             Bob       picnic
                             Sam       artshow", 
                       header=TRUE)
edgelist <- as.matrix(edgelist)
## Igraph Issues
igraph <- graph.edgelist(edgelist)
typevector <- bipartite.projection(igraph) 
# gets all FALSE
edgelist2 <- get.edgelist(igraph)
typevector <- bipartite.projection(edgelist2) 
# same thing
## tnet issues
tnet <- as.tnet(edgelist) 
# gives error: "There are duplicate events in the edgelist"
tnet <- as.tnet(edgelist2)
clusterMat <- clustering_local_tm(tnet)  
# gives error: "max not meaningful for factors"
onemode <- projecting_tm(tnet, method="Newman") 
# gives error: "arguments must have same length"
Gab*_*rdi 19
在igraph中,二分网络是具有type顶点属性的网络.此属性必须是逻辑的,并且必须是TRUE其中一个节点类型和FALSE其他节点类型.因此,要从边列表创建二分网络,只需创建一个常规图形,然后添加type顶点属性:
edgelist <- read.table(text="Person    Event
                         Amy       football
                         Bob       picnic
                         Sam       artshow", 
                   header=TRUE)
igraph <- graph.data.frame(edgelist)
V(igraph)$type <- V(igraph)$name %in% edgelist[,1]
igraph
# IGRAPH DN-B 6 3 -- 
# + attr: name (v/c), type (v/x)
'B'字母告诉您这是一个二分图.您可以通过以下方式创建此网络的单独投影:
bipartite.projection(igraph)
# $proj1
# IGRAPH UN-B 3 0 -- 
# + attr: name (v/c), type (v/x)
#
# $proj2
# IGRAPH UN-B 3 0 -- 
# + attr: name (v/c), type (v/x)
这将返回两个图表的列表.如果您认为投影可能太大,您可以先调用该bipartite.projection.size函数,这将为您提供两个投影中的顶点和边数.igraph图的内存要求是(4m + 2n)*8 + O(1)字节,其中'n'是顶点数,'m'是边数.