RStudio中的igraph包:Bipartite图投影错误

时间:2014-10-08 17:49:08

标签: r igraph bipartite

试图学习"螺母和螺栓"在R中的igraph包中的社会网络理论,我创建了一个基本的玩具示例,在阿尔及利亚内战的一年中恐怖袭击的二分图。顶点由恐怖犯罪者和目标组成,而边缘则代表攻击哪个目标的群体。

我可以绘制这种关系的一般单独图(以及网络中心性的基本分析),但是在创建网络的二分投影时遇到了问题。

根据@ GaborCsardi的建议,我只将igraph包加载到全局环境中,以确保snanetworks包不与命令冲突为igraph。

尽管如此,问题仍然存在:

 library(igraph)

 perpetrator <- c("Algerian Islamic Extremists", 
             "Salafist Group for Preaching and Fighting (GSPC)", 
             "Salafist Group for Preaching and Fighting (GSPC)", 
             "Algerian Islamic Extremists", 
             "Salafist Group for Preaching and Fighting (GSPC)", 
             "Muslim Extremists",
             "Armed Islamic Group (GIA)",
             "Armed Islamic Group (GIA)",
             "Armed Islamic Group (GIA)",
             "Muslim Militants")

 target <- c("Police", "Military", "Terrorists/Non-state Militia", "Police",
             "Military", "Private Citizens & Property", 
             "Private Citizens & Property", "Private Citizens & Property", 
             "Private Citizens & Property", "Private Citizens & Property")

 dat <- cbind(perpetrator, target)

 net <- graph.edgelist(as.matrix(dat)) 

 plot(net, main="Domestic Terrorism during the Algerian Civil War")

 V(net)$type <- FALSE

 V(net)$type[V(net)$name%in%dat$perpetrator] <- TRUE

 V(net)$type[V(net)$name%in%dat$target] <- TRUE

 bipartite.mapping(net)

 proj_net <- bipartite.projection(net, type=V(net)$type)

此时,RStudio会产生以下错误:

 Error in .Call("R_igraph_bipartite_projection", graph, types, as.integer(probe1),  :  
 At bipartite.c:198 : Non-bipartite edge found in bipartite projection, Invalid value

1 个答案:

答案 0 :(得分:2)

根据文档bipartite.mapping(...)

  

decides whether the vertices of a network can be mapped to two vertex types in a way that no vertices of the same type are connected.

如果可以执行此操作,则$type返回的列表中的bipartite.mapping(...)元素将标识每个顶点所属的子网络(通过TRUE或{{1} })。请注意,对于您的图表,有多种方法可以执行此操作。

您似乎(尝试)自己定义子网络。虽然一般来说,当你这样做时,子网不一定是二分的,在你的情况下它们是。因此,您只需使用FALSEbipartite.projection(...)划分到子网中,如下所示:

net

V(net)$type <- FALSE V(net)$type[V(net)$name%in%dat$perpetrator] <- TRUE proj_net <- bipartite.projection(net) 现在是一个包含两个元素的列表,即子图。

如果您想使用proj_net来识别子网,请按以下方式执行:

bipartite.mapping(...)

将所有目标组合在一起,也不是肇事者,但红色和绿色子网二分。

相关问题