Reputation:
I have a network in the form of an adjacency matrix, and I am trying to create a plot that shows the degree distribution of the network.
First of all, I used the function "graph.adjacency" to create an igraph object from the adjacency matrix, and I obtained the connectivity for each node with the "degree" function:
graphobj<-graph.adjacency(adjacencymatrix, mode="undirected")
degreenetwork<-degree(graphobj)
Then I have calculated the degree of each node with an other method:
degreenetwork2<-apply(adjacencymatrix, 1,sum)
and I have noticed that the degree of the nodes is not always preserved. In fact the the two methods give me different value of connectivity for the nodes. For example:
mean(degreenetwork)
[1] 156.068
mean(degreenetwork2)
[1] 78.034
min(degreenetwork)
[1] 17
min(degreenetwork2)
[1] 0
max(degreenetwork)
[1] 521
max(degreenetwork2)
[1] 452
Is there something wrong, or am I not using correctly the igraph package?
Regards
Gianni
Upvotes: 0
Views: 813
Reputation: 10825
You are possibly double counting edges, because your matrix is probably symmetric. Or maybe your matrix is not binary. It is hard to tell for sure, because you did not provide a reproducible example, so we have no idea what is in your matrix.
See How to make a great R reproducible example?.
Upvotes: 0