Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating assortativity in igraph

Tags:

r

igraph

I have a dataset as follows:

set.seed(123)
A = data.frame(rnorm(10),rnorm(10),rnorm(10),rnorm(10))

And then used igraph package to make a network out of the following:

inv<-cor(t(A))
inv[inv<0.5] <- 0
inv[inv==1] <- 0
g1 <- graph.adjacency(inv, mode = "undirected", diag=FALSE, weighted=TRUE)

Now to calculate the assortativity coefficeint of g1,

assortativity (g1, types1, types2 = NULL, directed = TRUE)

My question now is, how should I set "types", it says in the documentation, it is vertex values. What exactly is meant by that? I would like to calculate assortativity for any 5 vertex int he network. Could anyone tell me how this is done ?

like image 569
user2258452 Avatar asked Feb 12 '14 12:02

user2258452


People also ask

How do you calculate assortativity?

Assortativity coefficientˉf1=∑i,jϵEf(i)|E|,ˉf2=∑i,jϵEf(j)|E|. The assortativity coefficient is a Pearson correlation coefficient of some node property f between pairs of connected nodes. Positive coefficients imply assortativity, while negative ones imply disassortativity.

How to interpret assortativity?

The assortativity coefficient is the Pearson correlation coefficient of degree between pairs of linked nodes. Positive values of r indicate a correlation between nodes of similar degree, while negative values indicate relationships between nodes of different degree. In general, r lies between −1 and 1.


1 Answers

So I guess you want the nominal version of assortativity. Eg.

V(g1)$foo <- sample(1:3, replace=TRUE, vcount(g1))
assortativity.nominal(g1, types=V(g1)$foo)
# [1] -0.2270916

Types must be integers starting from 1. See details in the documentation.

like image 101
Gabor Csardi Avatar answered Sep 30 '22 02:09

Gabor Csardi