|
From: | Gábor Csárdi |
Subject: | Re: [igraph] Computing assortativity via degree correlation |
Date: | Wed, 28 Jan 2015 15:59:24 -0500 |
Hi, all!I've tried 3 different versions of code to calculate assortativity via degree correlation and two of them returned NA, while the third gave some reasonable numbers. My quistion is: can I trust it and why could 2 other receipts fail?1) First variant, which returned NA was taken from here: http://www.isk.kth.se/~shahabm/WSAnalysis/networks/NetworkAnalysis.rdeg <- degree(g)es <- get.edges(g, E(g)) + 1dc <- cor(deg[es[,1] ], deg[es[,2] ])2) The second one was from igraph wiki: http://igraph.wikidot.com/r-recipes#toc7assortativity <- function(graph){ deg <- degree(graph) deg.sq <- deg^2 m <- ecount(graph) num1 <- 0; num2 <- 0; den <- 0 edges <- get.edgelist(graph, names=FALSE)+1 num1 <- sum(deg[edges[,1]] * deg[edges[,2]]) / m num2 <- (sum(deg[edges[,1]] + deg[edges[,2]]) / (2 * m))^2 den <- sum(deg.sq[edges[,1]] + deg.sq[edges[,2]]) / (2 * m) return((num1-num2)/(den-num2)) }
3) And only this receipt gave me some reasonable numbers:correlation <- function(g, m="pearson") {el <- get.edgelist(g)d1 <- degree(g,el[,1])d2 <- degree(g,el[,2])if (sd(d1,d2)==0) return(1)co <- cor(d1,d2,method=m)return(co)}It also showed me this warning:Warning message:In if (na.rm) "na.or.complete" else "everything" :the condition has length > 1 and only the first element will be usedSo I basically want to know if I can trust the numbers, that were returned by the receipt #3. Of course it would be nice to know, why the first two receipts didn't work, but I'm not sure if I can send you the data I was working on to reproduce my results.Thanks in advance,Alex.(Social | Network | Data) AnalystJunior Research Fellow at the International Laboratory of Applied Network ResearchNational Research University Higher School of Economics
_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help
[Prev in Thread] | Current Thread | [Next in Thread] |