我有一个两种模式网络的边缘列表,类似于:
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
功能?
- 如何将 igraph 对象输入到 tnet 中?
- 如果一切都失败了,我该如何将具有重复边缘的数据帧输入到 tnet 中?
抱歉,如果这些是基本问题,但文档很少。
EDIT
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"
在 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”是边数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)