I am working with a network where I am trying to extract the mean value per vertex
of the jaccard similarity
. I am calculating this in R by using the igraph package. The similarity index estimates a value betweenn each two vertices
. The network has 177 vertices
, therefore 177
values. It may be easy, but I have not found out the best way to do it.
Asked
Active
Viewed 527 times
-1

Vlad
- 125
- 4
- 9
-
1Please create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), otherwise it is very hard for us to help solve your problem. – emilliman5 Mar 02 '17 at 13:24
-
OK, no problem: so I have: `SJaccard <- similarity(g, vids = V(g), mode = c("total"), loops = TRUE, method = c("jaccard"))`, where my network `g` is: `V(g)=177, and E(g)=10547`, it is very dense. The idea is to track vertex similarity. I want to test if the vertex average of `jaccard index` as measure of similarity decays as the network closeness increases. – Vlad Mar 02 '17 at 20:53
-
`igraph` gives me a list of 177 values per each vertex, I just want to substrack the mean of each. However, given that I am working with a graph object, It is difficult for me to estimate the maean value of the `jaccard_similarity` for each vertex. – Vlad Mar 02 '17 at 21:01
-
You have not made a reproducible example, yet – emilliman5 Mar 03 '17 at 03:07
-
ok, so if we have `g <- make_ring(5)` `similarity(g, method="jaccard")`, so we obtain a 5x5 matrix: `[,1] [,2] [,3] [,4] [,5]` `[1,] 1.0000000 0.0000000 0.3333333 0.3333333 0.0000000` `[2,] 0.0000000 1.0000000 0.0000000 0.3333333 0.3333333` `[3,] 0.3333333 0.0000000 1.0000000 0.0000000 0.3333333` `[4,] 0.3333333 0.3333333 0.0000000 1.0000000 0.0000000` `[5,] 0.0000000 0.3333333 0.3333333 0.0000000 1.0000000` and then, I need the similarity mean value of each five vertices. – Vlad Mar 03 '17 at 16:29
1 Answers
1
Sum the columns (or rows), subtract 1 (for the vertex similarity with itself), divide by n-1 rows (or columns)
library(igraph)
g <- make_ring(5)
m <-similarity(g, method="jaccard")
(colSums(m)-1)/(nrow(m)-1)
#[1] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667

emilliman5
- 5,816
- 3
- 27
- 37
-
excelent, thanks it works, I was using .rowMeans but, it was far from the correct answer. – Vlad Mar 03 '17 at 20:03