zpneal / backbone

R backbone package - Extract the backbone from weighted and unweighted networks
https://www.rbackbone.net
40 stars 8 forks source link

backbone.extract creates bidirectional backbones #27

Closed schochastics closed 3 years ago

schochastics commented 3 years ago

This is two issues in one (sorry...):

1) When the input is an igraph object, the output seems to always be a bidirectional graph instead of a undirected graph (see l2). 2) When the backbone is empty, there is an error message (see l1). This is probably due to setting the edge attribute sign

Here is a reprex:

library(igraph)
library(backbone)

g <- graph_from_incidence_matrix(davis)
l1 <- backbone.extract(sdsm(g),signed = FALSE)
#> This igraph object looks like an unweighted bipartite network of 18 agents and 14 artifacts.
#> Error in igraph::`E<-`(`*tmp*`, value = `*vtmp*`): invalid indexing
l2 <- backbone.extract(fixedcol(g),signed = FALSE)
#> This igraph object looks like an unweighted bipartite network of 18 agents and 14 artifacts.

l2
#> IGRAPH f01c0ca DNW- 18 16 -- 
#> + attr: name (v/c), weight (e/n), sign (e/n)
#> + edges from f01c0ca (vertex names):
#>  [1] EVELYN   ->LAURA     EVELYN   ->THERESA   EVELYN   ->BRENDA   
#>  [4] LAURA    ->EVELYN    LAURA    ->THERESA   LAURA    ->BRENDA   
#>  [7] THERESA  ->EVELYN    THERESA  ->LAURA     THERESA  ->BRENDA   
#> [10] BRENDA   ->EVELYN    BRENDA   ->LAURA     BRENDA   ->THERESA  
#> [13] KATHERINE->SYLVIA    SYLVIA   ->KATHERINE SYLVIA   ->NORA     
#> [16] NORA     ->SYLVIA
zpneal commented 3 years ago

Thanks. These are related to some new functions in v1.4 for interfacing with igraph. We'll get them corrected, but in the meantime here's an inelegant workaround for these two cases. It avoids using the problematic functions by working on the matrix object davis, then converts the result to an igraph object only at the end.

l1_star <- graph_from_adjacency_matrix(backbone.extract(sdsm(davis),signed = FALSE),mode="undirected") l2_star <- graph_from_adjacency_matrix(backbone.extract(fixedcol(davis),signed = FALSE),mode="undirected")

zpneal commented 3 years ago

It turns out this was also affecting the interface with statnet, but it's fixed now in the develop branch. We'll add it to master when we make the next CRAN release.