I am attempting to create a one-mode network of co-workers based on a bi-partite graph. I have a dataset consisting of people and the companies they worked at, plus the year they started and ended their time at any given company.
I want to project this undirected bipartite network, but only keep the edges that overlap in time, so that only those who worked at a company at the same time gets connected.
So in the example below I would like person3 not to be connected to person1 after projection, since person1 stopped working at company2 in 2008 before person3 started in 2009.
I also need the projected edges to have a weight attribute that increases whenever to nodes have worked together. For example the projected edge between person1 and person2 should be 2, since they worked together at company1 in 2009 and company 2 in 2007.
The real network has thousands of nodes, so the solution can't involve manually editing individual edges. I am working with igraph and tidygraph, but a solution from any other package is ok. Any solution that creates the desired one-mode network from the node- and edgelist without projecting from a bipartite/two-mode graph is also fine.
Reproducible example:
library(tidyverse)
library(igraph)
nodes_people <- data.frame(id=c("person1","person2","person3"), type="TRUE")
nodes_inst <- data.frame(id=c("company1","company2","company3"), type="FALSE")
nodes<-bind_rows(nodes_people, nodes_inst)
edges <- data.frame(from=c("person1","person1","person2","person3","person2","person3"),
to=c("company1","company2","company2","company3","company1","company2"),
start_date=c(2008,2007,2007,2003,2002,2009),
end_date=c(2010,2008,2012,2006,2009,2010))
g <- graph_from_data_frame(d=edges, vertices=nodes, directed=F)
is.bipartite(g)
g_one_mode<-bipartite_projection(g)$proj2
plot(g_one_mode)
Bipartite graph: bipartite network
One-mode network: one-mode