Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert an incidence matrix, of a bipartite network, to an unipartite projection

I would like to convert an incidence matrix of a bipartite procjection into a matrix of an unipartite projection.

For example:
I have this matrix, in which the columns are interacting with the respective rows when element equals > 0.

int <- matrix(rbinom(48, 2, 0.2),nrow=8,ncol=6)
colnames(int) <- letters[1:6]
rownames(int) <- letters[7:14]

I would like to generate a adjacency (square matrix) of the higher nodes (the columns), in which the new elements will be sum of times they shared the same interaction with the rows (g to n).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So if my int matrix is this one:

  a b c d e f
g 0 0 0 1 1 0
h 1 0 0 1 1 0
i 0 1 0 0 0 0
j 1 0 1 1 1 0
k 1 1 1 0 1 0
l 0 0 1 0 0 0
m 0 0 1 2 0 0
n 1 1 2 1 0 0

My unipartite projection resulting will be like:

  a b c d e f
a 0 2 3
b 2 0 2
c 3.. 0
d         3
e
f

In which the pair ab shared interaction with two rows (k and n) . The pair ac shared interaction with three rows (k , k and n), etc.

Any ideas?

>Solution :

`diag<-`(crossprod(df>0), 0)

  a b c d e f
a 0 2 3 3 3 0
b 2 0 2 1 1 0
c 3 2 0 3 2 0
d 3 1 3 0 3 0
e 3 1 2 3 0 0
f 0 0 0 0 0 0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading