Calculates a measure of diversity for all vertices.
Usage
diversity(graph, weights = NULL, vids = V(graph))
Arguments
- graph
The input graph. Edge directions are ignored.
- weights
NULL
, or the vector of edge weights to use for the computation. IfNULL
, then the ‘weight’ attibute is used. Note that this measure is not defined for unweighted graphs.- vids
The vertex ids for which to calculate the measure.
Details
The diversity of a vertex is defined as the (scaled) Shannon entropy of the weights of its incident edges: D(i)=H(i)logki and H(i)=−ki∑j=1pijlogpij, where pij=wij∑kil=1Vil, and ki is the (total) degree of vertex i, wij 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()
,
betweenness()
,
closeness()
,
eigen_centrality()
,
harmonic_centrality()
,
hub_score()
,
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 0 1 1 0 0 1 1 NaN 0 NaN 1 1 1 1 0 1 1 0
#> [20] 1
diversity(g2)
#> [1] 0.0000000 0.0000000 0.9912105 0.1954131 0.2786455 NaN 0.9285801
#> [8] NaN 0.9562562 0.8678366 0.9145202 0.0000000 0.9606785 NaN
#> [15] 0.0000000 0.9837941 0.0000000 0.0000000 0.0000000 0.8888561
diversity(g3)
#> [1] 0.9153007 0.9963839 0.7610137 0.9986502 0.7908580 0.6775001 0.9359162
#> [8] 0.9681371 0.6402843 0.9446303 0.8001961 0.9568925 0.8956848 0.2837485
#> [15] 0.8343112 0.8661485 0.8991006 0.5628532 0.8944529 0.9736941