R igraph manual pages

Use this if you are using igraph from R

Graph diversity

Description

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. If NULL, 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)/log(k[i])

and

H(i) = -sum(p[i,j] log(p[i,j]), j=1..k[i]),

where

p[i,j] = w[i,j] / sum(w[i,l], l=1..k[i]),

and k[i] is the (total) degree of vertex i, w[i,j] is the weight of the edge(s) between vertices i and j.

For vertices with degree less than two the function returns NaN.

Value

A numeric vector, its length is the number of vertices.

Author(s)

Gabor Csardi csardi.gabor@gmail.com

References

Nathan Eagle, Michael Macy and Rob Claxton: Network Diversity and Economic Development, Science 328, 1029–1031, 2010.

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)
diversity(g2)
diversity(g3)

[Package igraph version 1.2.4 Index]