Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bipartite_mapping working unexpectedly when using the get_igraph function #2

Open
Sebastian-Montoya-B opened this issue Nov 29, 2024 · 0 comments

Comments

@Sebastian-Montoya-B
Copy link

Dear emln package developers.

First of all, I want to thank you for your package, it has been very useful for my data analysis.

While I was using it (version 1.0), I found some unexpected behaviors when I wanted to transform a multilayer bipartite network into igraph object. In a few words, the get_igraph function seems to be having trouble in assigning the "type" of the node when there are nodes with no interactions in both layers while other nodes of the same type do have interactions in both layers. See the example below.

library(igraph)
library(emln)



mat1<-matrix(c(1,1,1,0,
         1,1,1,0,
         1,1,1,0,
         0,0,0,1), byrow=T, ncol=4, dimnames=list(paste0("A", 1:4), paste0("P", 1:4)))

mat2<-matrix(c(1,1,1,0,
               1,1,1,0,
               1,1,1,0,
               0,0,0,1), byrow=T, ncol=4, dimnames=list(paste0("A", 5:8), paste0("P", 2:5)))


layer_attrib <- tibble(layer_id=1:2,
                       layer_name=c('l1','l2'))

interlayer<-tibble(layer_from=rep("l1", 3),
                               node_from=c("P2", "P3", "P4"),
                               layer_to=rep("l2", 3),
                               node_to=c("P2", "P3", "P4"),
                               weight=1)

multilayernit<-
  create_multilayer_network(list_of_layers = list(mat1, mat2),
                            layer_attributes = layer_attrib,
                            interlayer_links = interlayer,
                            bipartite = TRUE,
                            directed = FALSE
  )


ig<-get_igraph(multilayernit, bipartite=TRUE, directed=FALSE)

data.frame(name=V(ig$layers_igraph$l1)$name, type=V(ig$layers_igraph$l1)$type)
data.frame(name=V(ig$layers_igraph$l2)$name, type=V(ig$layers_igraph$l2)$type)

data.frame(name=V(ig$layers_igraph$l1)$name, type=V(ig$layers_igraph$l1)$type)
name type
1 A1 FALSE
2 A2 FALSE
3 A3 FALSE
4 A4 FALSE
5 A5 FALSE
6 A6 FALSE
7 A7 FALSE
8 A8 FALSE
9 P1 TRUE
10 P2 TRUE
11 P3 TRUE
12 P4 TRUE
13 P5 FALSE
data.frame(name=V(ig$layers_igraph$l2)$name, type=V(ig$layers_igraph$l2)$type)
name type
1 A1 FALSE
2 A2 FALSE
3 A3 FALSE
4 A4 FALSE
5 A5 FALSE
6 A6 FALSE
7 A7 FALSE
8 A8 FALSE
9 P1 FALSE
10 P2 TRUE
11 P3 TRUE
12 P4 TRUE
13 P5 TRUE

The final data frame should be showing, in the "type" column, all FALSE for As, and all TRUE for Ps. However, there is a FALSE in P5. There is a similar problem in the graph of the second layer (P1 is FALSE but it should be TRUE). Both P1 and P5 are nodes exclusively interacting in a single layer. As a consequence, plotting and further analysis using can be compromised.

If there is something I am missing, please, let me know.

Thank you very much for your attention.

Sincerely,

Sebastian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant