Calculating assortativity in igraph
igraph, r
Solution
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.
Problem
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 ?