Last active
October 29, 2015 15:47
-
-
Save gweissman/2402935 to your computer and use it in GitHub Desktop.
Calculate Newman's assortativity coefficient for a mixing matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculate the assortativity coefficient for a mixing matrix of a graph | |
# ref: MEJ Newman, 'Mixing patterns in networks', Phys Rev E 67, 026126 (2003) | |
# | |
# define assortativity coefficient as | |
# trace (m) - sum (m^2) | |
# ac = ------------------------- | |
# 1 - sum (m^2) | |
# | |
# where m is the mixing matrix of a graph | |
assortcoeff <- function(m) { | |
tr <- sum(diag(m)) | |
sumsq <- sum (rowSums(m)*colSums(m)) | |
(tr - sumsq) / (1 - sumsq) | |
} |
This solution should generalize for both directed and undirected graphs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, what would be the case for directed graph?