简体   繁体   中英

Working on bipartite networks with igraph : problem with basic measures (density, normalized degree)

I'm new to bipartite.network analysis and i've some trouble with basic measures. I'm trying to work on bipartite.networks without projecting in 1-mode graphs . My problems come from the fact that the igraph package allows to create bipartite graphs but that the measures do not seem to adapt to the specificity of these graphs.

So, my general question is how do you do when you work directly on bipartite.networks?

Here a concrete exemple with density

## Working with an incidence matrix (sample) with 47 columns and 10 rows (unweighted / undirected)
# Want to compute basic global index like density with igraph
library(igraph)
g <- graph.incidence(m, directed = F )
graph.density(g) # result = 0.04636591

# Now trying to compute basic density for a bipartite graph without igraph (number of edges divided  by the product of the two types of vertices)
library(Matrix)
d <- nnzero(m)/ (ncol(m)*nrow(m)) # result 0.1574468

# It seems that bipartite package does the job 
library(bipartite)

networklevel(m, index=c("connectance")) # result 0.1574468

But the bipartite package is very specific to ecology fields and lot of measures are designed to food web and interaction between species (and some, like clustering coefficient, don't seem to take into account the bipartite nature of the graph: eg compute 4-cycles).

So, are there simpler ways to work on bipartite.networks with igraph ? To measure some global indexes (density, clustering coefficient with 4-cycles, I know that .net does this but my actual.networks are too large), and to normalize local indexes like degree, closeness, betweenness centralities taking into account the bipartite specificity (like in Borgatti SP, Everett MG, 1997, « Network analysis of 2-mode data », Social Networks)?

Any advice will be appreciated !

Below the code to reproduce the sample of my matrix "m"

 m <- structure(c(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 
0, 0, 0, 1, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0), .Dim = c(10L, 47L), .Dimnames = list(
    c("02723", "13963", "F3238", "02194", "15051", "04477", "02164", 
    "06283", "04080", "08304"), c("1185241", "170063", "10350868", 
    "217831", "2210247", "2262963", "1816670", "1848354", "2232593", 
    "146214", "1880252", "2261639", "2262581", "2158177", "1850147", 
    "2262912", "146412", "2262957", "1566083", "1841811", "146384", 
    "216281", "2220957", "1846986", "1951567", "1581130", "105343", 
    "1580240", "170654", "1796236", "1835553", "1835848", "146400", 
    "1174872", "1283240", "2253354", "1283617", "146617", "160263", 
    "2263115", "184745", "1809858", "1496747", "10346824", "148730", 
    "2262582", "146268")))

Density: you already got it

Degree degv1 <- degree(g, V(g)[type == FALSE]) degv2 <- degree(g, V(g)[type == TRUE])

Normalized degree: divise by the vcount of the other node category

degnormv1 <- degv1/length(V(g)[type == TRUE]) degnormv2 <- degv2/length(V(g)[type == FALSE])

No answer regarding closeness, betweenness nor clustering coefficient

For the normalized degree, here a solution without igraph

normalizedegreeV1 <- data.frame(ND = colSums(m)/nrow(m))

normalizedegreeV2 <- data.frame(ND = rowSums(m)/ncol(m))

but that leaves the other questions about centrality measures open...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM