[英]How to create a bipartite network in R with igraph or tnet
I have an edgelist for a two mode network, similar to this: 我有一个双模网络的边缘列表,类似于:
person Event
Amy football_game
Sam picnic
Bob art_show
I want to perform an analysis on this in R, but seemingly everything I try fails. 我想在R中对此进行分析,但看起来我尝试的一切都失败了。 Converting it to a one mode network runs into memory limitations, and I can't figure out how to analyze it as bipartite in either igraph or tnet.
将其转换为单模式网络会遇到内存限制,我无法弄清楚如何在igraph或tnet中将其分析为二分。
In igraph, bipartite.projection
gives me all FALSE
, on the igraph object created using 在igraph中,
bipartite.projection
给我所有的FALSE
,在使用的igraph对象上创建
net <- graph.edgelist(myobject)
On tnet, I can't convert the igraph net to a tnet one, and when I try to use the original data frame, it refuses because of duplicates in the graph. 在tnet上,我无法将igraph网转换为tnet网,当我尝试使用原始数据框时,它会因图中的重复而拒绝。
So answers to any of the following would be super appreciated: 因此,以下任何一个的答案将非常感激:
bipartite.mapping
function? bipartite.mapping
函数? Sorry if these are basic questions, but there's very little documentation. 很抱歉,如果这些是基本问题,但文档很少。
Example: 例:
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"
In igraph a bipartite network is one that has a type
vertex attribute. 在igraph中,二分网络是具有
type
顶点属性的网络。 This attribute must be logical and must the TRUE
for one of the node types and FALSE
for the others. 此属性必须是逻辑的,对于其中一个节点类型必须为
TRUE
,对于其他节点类型必须为FALSE
。 So to create a bipartite network from your edge list, you simply create a regular graph and then add the type
vertex attribute: 因此,要从边列表创建二分网络,只需创建一个常规图形,然后添加
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)
The 'B' letter tells you that this is a bipartite graph. 'B'字母告诉您这是一个二分图。 You can create the unipartite projections of this network via:
您可以通过以下方式创建此网络的单独投影:
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)
This will return a list of two graphs. 这将返回两个图表的列表。 If you think that the projection might be too big, you can first call the
bipartite.projection.size
function, this will give you the number of vertices and edges in both projections. 如果您认为投影可能太大,可以先调用
bipartite.projection.size
函数,这将为您提供两个投影中顶点和边的数量。 The memory requirement for an igraph graph is (4m+2n)*8+O(1) bytes, where 'n' is the number of vertices and 'm' is the number of edges. igraph图的内存要求是(4m + 2n)* 8 + O(1)字节,其中'n'是顶点数,'m'是边数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.