I am working with a network where I am trying to extract the mean value per vertexof 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 458 times
-1
Vlad
- 95
- 3
- 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 – 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 – 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,538
- 3
- 24
- 36
-
excelent, thanks it works, I was using .rowMeans but, it was far from the correct answer. – Vlad Mar 03 '17 at 20:03