0
votes

I am trying to get the weighted degree and unweighted degree distribution of a matrix with weighted edges in igraph. I used the graph.adjacency function such as

newMatrix<-graph.adjacency(matrix, weighted=NULL, mode="undirected", diag=FALSE) 

But the weighted argument is not given me the result I expected. For a 3x3 matrix for example with the following values:

    [,1][,2][,3]
[1,]  1   2   2
[2,]  2   2   0
[3,]  2   0   3

I would expect with the argument weighted=NULL and diag=FALSE an adjacency matrix such as:

    [,1][,2][,3]
[1,]  .   1   1
[2,]  1   .   .
[3,]  1   .   .

So the degree distribution for unweighted edges vector would be degree(2,1,1). Nevertheless the function is returning a weighted matrix. The returning adjacency matrix is:

    [,1][,2][,3]
[1,]  .   2   2
[2,]  2   .   .
[3,]  2   .   .

I have tried to change the weighted argument to TRUE and de modes to min, max... but the results always give me back a weighted matrix.

1

1 Answers

0
votes

When weight=NULL and mode=undirected, graph.adjacency interprets the i,j entry of the (symmetric) adjacency matrix as the number of edges between i,j. You can change this interpretation by changing the mode parameter (see the documentation).

To count each edge only once (which appears to be what you want to do), you can just rescale the input matrix

m <- matrix(c(1,2,2,2,2,0,2,0,3),nrow=3,ncol=3,byrow=TRUE)
mscaled <-ifelse(m>=1,1,0)
newMatrix<-graph.adjacency(mscaled, weighted=NULL, mode="undirected", diag=FALSE)