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

Reply via email to