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 ?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With