I'm trying to calculate different network statistics with the following (demo) data
BLM | NPS | USFWS | USFS | Bureau of Reclamation | |
---|---|---|---|---|---|
BLM | 10 | 1 | 8 | 2 | 1 |
NPS | 1 | 3 | 2 | 0 | 0 |
USFWS | 8 | 2 | 22 | 5 | 2 |
USFS | 2 | 0 | 5 | 5 | 0 |
Bureau of Reclamation | 1 | 0 | 2 | 0 | 2 |
When it came to running network statistics I've run into a couple problems.
- The first part of my question is why the following igraph objects have different values for calculating average weighted degree (the average # of edges connected to each node / total number of nodes)
library(igraph)
library(reshape2)
diag(mat) <- NA #remove diagonal (this was done because to creating an adjacency matrix from edge & node list "igraph[]" leaves the diagonal blank. Source - http://pablobarbera.com/big-data-upf/html/02a-networks-intro-visualization.html
salfTmatlist <- mat %>% melt() #change into list
#create igraph objects
salfTnet <- graph_from_data_frame(d=salfTmatlist, directed=T)
Partner_Network <- graph_from_adjacency_matrix(mat)
#calculate average weighted degree
mean(degree(salfTnet), mode = "total")
mean(degree(Partner_Network), mode = "total")
#checking calculations by hand
added <- rowSums(mat, na.rm = TRUE) #this gives the correct number of edges across each node
mean(added)
The check calculation seems to be the same as the calculation done with the igraph object set from the adjacency matrix but I don't know why setting the igraph object from the same data with different functions makes a difference in the calculation.
- For calculating modularity, I can't check my work and I get different answer here again
modularity(Partner_Network, V(Partner_Network))
modularity(salfTnet, V(salfTnet))
Any thoughts on the following:
- why there are different values from functions being applied to the same data?
- Which calculations are correct? (based on the check it seems like I should stick to the igraph object generated from "graph_from_adjacency_matrix" but I'm not sure)