Hi, Gabor! Thanks for reply!
I didn't know about that function. I only knew about assortativity() function, but its 'types' parameters were not clear enough for me last time and I used this receipt for measuring attribute-based homophily: http://www.babelgraph.org/wp/?p=351 That's why this time I googled "igraph degree correlation" instead of "igraph assortativity". BTW, Your function returned slightly different results: -0.1118586 instead of -0.1007182 for one graph (which was a network of retweets) and 0.09513074 instead of 0.1701178 for the mentions network from the same data. I think I'll stick to the results of your function though. Best, Alex. (Social | Network | Data) Analyst Junior Research Fellow at the International Laboratory of Applied Network Research National Research University Higher School of Economics http://anr.hse.ru/en/ http://jarens.ru ru.linkedin.com/in/semenoffalex/ https://www.facebook.com/semenoffalex https://twitter.com/jarens skype: semenoffalex tel: +7 926 602 25 51 2015-01-28 23:59 GMT+03:00 Gábor Csárdi <[email protected]>: > How about calling the assortativity.degree function? > http://igraph.org/r/doc/assortativity.html > > Gabor > > On Wed, Jan 28, 2015 at 3:57 PM, Alexander Semenov <[email protected] > > wrote: > >> 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.r >> deg <- degree(g) >> es <- get.edges(g, E(g)) + 1 >> dc <- cor(deg[es[,1] ], deg[es[,2] ]) >> >> 2) The second one was from igraph wiki: >> http://igraph.wikidot.com/r-recipes#toc7 >> >> assortativity <- 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) >> } >> >> I found it in this book: >> https://books.google.ru/books?id=Bdc1VFp7OZMC&pg=PA37&lpg=PA37&dq=igraph+degree+correlation&source=bl&ots=mJ6ivAJupU&sig=pYWtaE533vAbXUfKTwWLq8AmLaQ&hl=en&sa=X&ei=FCvJVIWdDsvcywPd9oDACA&redir_esc=y#v=onepage&q=igraph%20degree%20correlation&f=false >> >> 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 used >> >> So 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) Analyst >> >> Junior Research Fellow at the International Laboratory of Applied Network >> Research >> National Research University Higher School of Economics >> http://anr.hse.ru/en/ >> >> http://jarens.ru >> ru.linkedin.com/in/semenoffalex/ >> https://www.facebook.com/semenoffalex >> https://twitter.com/jarens >> >> skype: semenoffalex >> tel: +7 926 602 25 51 >> >> >> _______________________________________________ >> igraph-help mailing list >> [email protected] >> https://lists.nongnu.org/mailman/listinfo/igraph-help >> >> > > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help > >
_______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
