In an attempt to learn the "nuts-and-bolts" of social network theory within the igraph package in R, I created a basic toy example of a bipartite graph of terror attacks during a single year of the Algerian Civil War. The vertices consist of terror perpetrators and targets, while the edges represent which group attacked which target.
I can plot the general unipartite graph of this relationship (as well as basic analyses of network centrality), but am having problems creating a bipartite projection of the network.
Per @GaborCsardi's suggestion, I've only loaded the igraph package into the global environment, as to ensure that the sna or networks packages do not conflict with the commands for igraph.
Nonetheless, the problem persists:
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)
At which point, RStudio produces the following error:
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

datas a matrix (usingcbind(...)), and you cannot reference columns in a matrix using$. Usedat<-data.frame(peretrator,target). - jlhoward$type=TRUEfor all perpetrators, then setting$type=TRUEfor all targets. SoV(net)$typeis TRUE always. What is the point of doing this?? - jlhoward