igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Computing assortativity via degree correlation


From: Alexander Semenov
Subject: [igraph] Computing assortativity via degree correlation
Date: Wed, 28 Jan 2015 23:57:33 +0300

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)
}


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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]