为了在 R 中的 igraph 包中学习社交网络理论的“基本要素”,我创建了一个基本的玩具示例,该示例是阿尔及利亚内战一年期间恐怖袭击的二分图。顶点由恐怖肇事者和目标组成,而边缘代表哪个团体攻击了哪个目标。
我可以绘制这种关系的一般单部分图(以及网络中心性的基本分析),但是在创建网络的二部分投影时遇到问题。
根据@GaborCsardi 的建议,我只将 igraph 包加载到全局环境中,以确保sna
ornetworks
包不会与 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