Degree Centrality
Degree is a simple centrality measure that counts how many neighbors a
node has. If the network is directed, we have two versions of the
measure: in-degree is the number of in-coming links, or the number of
predecessor nodes; out-degree is the number of out-going links, or the
number of successor nodes. Typically, we are interested in in-degree,
since in-links are given by other nodes in the network, while out-links
are determined by the node itself. Degree centrality thesis reads as
follows:
A node is important if it has many neighbors, or, in the directed case, if there are many other nodes that link to it.
Math
Let A=(ai,j) be the adjacency matrix of a directed graph. The in-degree centrality xi of node i is given by:
xi=∑kak,i
or in matrix form (e is a vector with all components equal to unity):
x=eA
The out-degree centrality yi of node i is given by:
yi=∑kai,k
or in matrix form:
y=eAT
Related to degree is friendship paradox, which is a phenomenon observed by sociologist Scott L. Feld. It claims that, on average,
I have fewer friends than my friends have :-(
On a social network, it formally says that the mean node degree:
μ1=∑ikin
is less than or equal to the mean neighbors degree:
μ2=∑i,jai,jkj∑i,jai,j
Indeed:
μ2=∑i,jai,jkj∑i,jai,j=∑j∑iai,jkj∑j∑iai,j=∑jkj∑iai,j∑jkj=∑jkj⋅kj∑iki=⟨k2⟩⟨k⟩
where ⟨k2⟩ is the quadratic mean of degrees and ⟨k⟩ is the mean of degrees. Hence:
μ2−μ1=⟨k2⟩⟨k⟩−⟨k⟩=⟨k2⟩−⟨k⟩2⟨k⟩=σ2⟨k⟩≥0
Since both the variance σ2 and the mean ⟨k⟩ of the degree distribution are positive quantities, we have that the inequality holds.
In particular we have that μ1=μ2 if and only if σ2=0
if and only if all nodes have the same degree (the graph is regular).
On the other hand, when the distribution of degrees is skewed (the
typical case), the inequality is proper. This because hub nodes, which
are nodes with a high degree, are counted once in μ1, but are counted many times in μ2, because they are, by definition, friends on many others. Hence, the mean μ2 is computed on a biased sample.
Code
The built-in function degree computes degree centrality and strength computes weighted degree centrality.
A user-defined function degree.centrality follows:
# Degree centrality
# INPUT
# g = graph
# mode = degree mode ("in" for in-degree, "out" for out-degree, "all" for total degree)
degree.centrality = function(g, mode) {
A = as_adjacency_matrix(g, sparse=FALSE);
e = rep(1, n);
if (mode == "in") x = e %*% A
if (mode == "out") x = e %*% t(A)
if (mode == "all") x = e %*% (A + t(A));
return(as.vector(x));
}
Example
A graph with nodes labelled with their in-degree centrality follows:
Next is the same graph with nodes labelled with their out-degree centrality: