Calculates a measure of diversity for all vertices.
Usage
diversity(graph, weights = NULL, vids = V(graph))
Details
The diversity of a vertex is defined as the (scaled) Shannon entropy of the weights of its incident edges: $$D(i)=\frac{H(i)}{\log k_i}$$ and $$H(i)=-\sum_{j=1}^{k_i} p_{ij}\log p_{ij},$$ where $$p_{ij}=\frac{w_{ij}}{\sum_{l=1}^{k_i}}V_{il},$$ and \(k_i\) is the (total) degree of vertex \(i\), \(w_{ij}\) is the weight of the edge(s) between vertices \(i\) and \(j\).
For vertices with degree less than two the function returns NaN
.
References
Nathan Eagle, Michael Macy and Rob Claxton: Network Diversity and Economic Development, Science 328, 1029–1031, 2010.
See also
Centrality measures
alpha_centrality()
,
authority_score()
,
betweenness()
,
closeness()
,
eigen_centrality()
,
harmonic_centrality()
,
hits_scores()
,
page_rank()
,
power_centrality()
,
spectrum()
,
strength()
,
subgraph_centrality()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
g1 <- sample_gnp(20, 2 / 20)
g2 <- sample_gnp(20, 2 / 20)
g3 <- sample_gnp(20, 5 / 20)
E(g1)$weight <- 1
E(g2)$weight <- runif(ecount(g2))
E(g3)$weight <- runif(ecount(g3))
diversity(g1)
#> [1] 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 1
diversity(g2)
#> [1] NaN 0.0000000 0.8608477 0.8116523 0.0000000 0.0000000 0.0000000
#> [8] 0.5435621 0.8936834 0.0000000 NaN 0.0000000 0.0000000 0.9671509
#> [15] 0.8529370 0.0000000 0.0000000 0.8905518 0.6328877 0.0000000
diversity(g3)
#> [1] 0.9736305 0.9305943 0.7838024 0.8961058 0.9096906 0.9124161 0.9518659
#> [8] 0.6725178 0.0000000 0.8498885 0.9364498 0.4591131 0.9562086 0.9493656
#> [15] 0.9792812 0.9035640 0.8744335 0.8990292 0.9880011 0.9681798