Skip to content

incidence and adjacency matrix conversion

4 messages · Philip Leifeld, David Barron, Martin Maechler

#
Dear all,

how can I convert an m x n incidence matrix into an m x m adjacency 
matrix or an n x n adjacency matrix? The current matrix contains binary 
data, hence the new matrix would contain counts of common occurrences.

Thank you for your help.

Phil
#
I think you can do this using the network package.  Look at the
as.network.matrix and as.matrix.network functions, for example.
On 05/12/06, Philip Leifeld <Philip.Leifeld at uni-konstanz.de> wrote:

  
    
1 day later
#
Thanks, David. I tried converting my rectangular matrix to a network 
object and then back to a square matrix. This works for a small 
artificial dataset (e.g. 2x5), but when I try this on my 1790x45 or 
transposed 45x1790 matrix, R keeps working for a couple of minutes and 
then crashes completely without having saved any data first. I assume 
something is wrong with my data?

Cheers
Philip
David Barron wrote:
#
Phil> Dear all,
    Phil> how can I convert an m x n incidence matrix into an m x m adjacency 
    Phil> matrix or an n x n adjacency matrix? The current matrix contains binary 
    Phil> data, hence the new matrix would contain counts of common occurrences.

You have not given a self contained reproducible example
which would even be useful in such a case..

But just to be sure that the solution is not as simple as I
thought it was -- namely I thought, that for binary matrices,
crossprod()  and tcrossprod() would give what you'd want :
[1,] . . | .
 [2,] . . . .
 [3,] . . . .
 [4,] | . . .
 [5,] . | . |
 [6,] | . . .
 [7,] | | . |
 [8,] . | . .
 [9,] . . | |
[10,] . | . .
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    .    .    .    .    .    .    .    1     .
 [2,]    .    .    .    .    .    .    .    .    .     .
 [3,]    .    .    .    .    .    .    .    .    .     .
 [4,]    .    .    .    1    .    1    1    .    .     .
 [5,]    .    .    .    .    2    .    2    1    1     1
 [6,]    .    .    .    1    .    1    1    .    .     .
 [7,]    .    .    .    1    2    1    3    1    1     1
 [8,]    .    .    .    .    1    .    1    1    .     1
 [9,]    1    .    .    .    1    .    1    .    2     .
[10,]    .    .    .    .    1    .    1    1    .     1
[,1] [,2] [,3] [,4]
[1,]    3    1    .    1
[2,]    1    4    .    2
[3,]    .    .    2    1
[4,]    1    2    1    3
Phil> Thank you for your help.

you're welcome (if it did help).

Martin Maechler, ETH Zurich