Centrality API Reference

Vertex-level centrality indices with R sna's names and semantics. None of them is a method of a Graphs.jl function; see the R concordance for the mapping from sna and from the pre-0.2 names.

Degree

SNA.degreecent — Function
degreecent(net; cmode=:freeman, rescale=false, normalized=false, diag=false,
           ignore_eval=true, attr=:weight, missing=:error) -> Vector{Float64}

Degree centrality of every vertex: R sna::degree. (The function is named degreecent, after sna's own naming of centrality indices such as infocent, because degree is Graphs.jl's vertex degree, which SNA re-exports unchanged.)

Arguments

  • cmode: :freeman (in + out degree, sna's default), :indegree or :outdegree. Ignored for undirected networks, where each edge adds 1 to both endpoints (sna's gmode="graph").
  • rescale=true: divide by the sum of the scores, as sna's rescale=TRUE.
  • normalized=true: divide by the largest possible degree, n−1 (or 2(n−1) for Freeman degree of a directed network), plus 1 with diag=true. This is not an sna option.
  • diag=false: self-loops are ignored (sna's diag=FALSE); diag=true counts a loop once.
  • ignore_eval=true: binary ties. ignore_eval=false, attr=:weight sums the numeric edge attribute attr (sna's default ignore.eval=FALSE).
  • missing=:error: a network with masked (unobserved) dyads is refused; missing=:face counts each masked dyad at its stored face value (see NetworkCore.require_observed).

Example

using SNA
net = network(4)
add_edges!(net, [(1, 2), (1, 3), (2, 3), (3, 4)])
degreecent(net)                      # [2.0, 2.0, 3.0, 1.0]  (Freeman)
degreecent(net; cmode=:indegree)     # [0.0, 1.0, 2.0, 1.0]
source

Path-based centrality

SNA.betweenness — Function
betweenness(net; cmode=:directed, rescale=false, normalized=false,
            missing=:error) -> Vector{Float64}

Shortest-path betweenness of every vertex: R sna::betweenness. The default is the raw score, the number of geodesics between other pairs that pass through the vertex (each unordered pair counted once on an undirected network).

Arguments

  • cmode: :directed (sna's default) uses directed geodesics; :undirected symmetrizes a directed network first (an arc in either direction is a tie). sna's other path-weighting modes (endpoints, proximalsrc, …) are not implemented and raise an ArgumentError.
  • rescale=true: divide by the sum of the scores (sna's rescale=TRUE).
  • normalized=true: Freeman's normalization, divide by the number of pairs of other vertices, (n−1)(n−2) directed or (n−1)(n−2)/2 undirected, giving scores in [0, 1]. This is not an sna option.
  • missing=:error: masked (unobserved) dyads are refused; missing=:face builds the paths from their stored face values.

Example

using SNA
star = network(4; directed=false)
add_edges!(star, [(1, 2), (1, 3), (1, 4)])
betweenness(star)                    # [3.0, 0.0, 0.0, 0.0]
betweenness(star; normalized=true)   # [1.0, 0.0, 0.0, 0.0]
source
SNA.closeness — Function
closeness(net; cmode=:directed, rescale=false, missing=:error) -> Vector{Float64}

Closeness centrality of every vertex: R sna::closeness.

Arguments

  • cmode:

    • :directed (default): Freeman closeness (n−1) / Σⱼ d(i,j) over directed geodesics. A vertex that cannot reach every other vertex scores 0, as in sna, so every score of a disconnected network is 0.
    • :undirected: the same on the weak symmetrization.
    • :suminvdir / :suminvundir: Σⱼ 1/d(i,j) / (n−1), with 1/∞ = 0, directed or symmetrized; defined on disconnected networks.
    • :gil_schmidt: Gil–Schmidt power index, Σⱼ 1/d(i,j) over the vertices i reaches divided by their number (0 if it reaches none).

    On an undirected network :directed and :undirected (and the two suminv modes) coincide.

  • rescale=true: divide by the sum of the scores (sna's rescale=TRUE).

  • missing=:error: masked (unobserved) dyads are refused; missing=:face builds the paths from their stored face values.

Graphs.jl's closeness_centrality scales each vertex by the share of the network it reaches instead; that convention is Graphs.jl's, not sna's.

Example

using SNA
path = network(3; directed=false)
add_edges!(path, [(1, 2), (2, 3)])
closeness(path)                       # [0.6667, 1.0, 0.6667]
closeness(path; cmode=:suminvundir)   # [0.75, 1.0, 0.75]
source
SNA.flowbet — Function
flowbet(net; ignore_eval=true, attr=:weight, diag=false, missing=:error) -> Vector{Float64}

Freeman flow betweenness of every vertex: R sna::flowbet,

f(v) = Σ_{i,j ≠ v} [maxflow(i → j) − maxflow(i → j | v removed)]

with edge capacities from the adjacency matrix. Pairs are ordered for directed networks and unordered for undirected networks, and raw scores are returned (sna's default). Ties are binary by default (ignore_eval=true); sna's default ignore.eval=FALSE uses edge values, which ignore_eval=false, attr=:weight reproduces.

missing=:error refuses masked dyads; missing=:face takes their stored face values as capacities.

Example

using SNA
path = network(3; directed=false)
add_edges!(path, [(1, 2), (2, 3)])
flowbet(path)                        # [0.0, 1.0, 0.0]
source

Spectral and information centrality

SNA.evcent — Function
evcent(net; rescale=false, tol=1e-10, diag=false, ignore_eval=true,
       attr=:weight, missing=:error) -> Vector{Float64}

Eigenvector centrality: R sna::evcent. The scores are the principal right eigenvector of the adjacency matrix (a directed network weights an actor by the centrality of the actors it sends ties to), oriented non-negative with unit Euclidean norm.

The eigenvector of the largest real eigenvalue is taken by a direct eigen-decomposition, which is sna's use.eigen=TRUE (up to sign). sna's default power iteration does not converge on bipartite or other periodic networks and then returns a vector that is not an eigenvector; this function does not have that failure. When the leading eigenvalue is repeated the eigenvector is not unique and a warning says so. When the leading eigenvalue is 0 (an empty network, or a directed acyclic one) there is no positive eigenvector and every score is NaN, as sna returns.

Arguments

  • rescale=true: divide by the sum of the scores (sna's rescale=TRUE).
  • tol: relative tolerance of the repeated-eigenvalue check.
  • diag, ignore_eval, attr: as in degreecent; weights must be non-negative.
  • missing=:error: masked dyads are refused; :face uses their stored face values.

Example

using SNA
path = network(3; directed=false)
add_edges!(path, [(1, 2), (2, 3)])
evcent(path)                         # [0.5, 0.7071, 0.5]
source
SNA.bonpow — Function
bonpow(net; exponent=1.0, rescale=false, tol=1e-7, diag=false,
       ignore_eval=true, attr=:weight, missing=:error) -> Vector{Float64}

Bonacich power centrality: R sna::bonpow,

c = α (I − β A)⁻¹ A 𝟙,   with α chosen so that Σᵢ cᵢ² = n.

Arguments

  • exponent: the attenuation β. The power series converges for |β| < 1/λ_max; a positive β rewards ties to well-connected actors, a negative β ties to poorly connected ones.
  • rescale=true: divide by the sum of the scores (sna's rescale=TRUE).
  • tol: (I − βA) is treated as singular when the reciprocal of its 1-norm condition number is below tol, the test R's solve(tol=) applies. A singular system gives NaN scores and a warning. (A determinant test, used before 0.2.0, underflows on large well-conditioned systems.)
  • diag, ignore_eval, attr: as in degreecent.
  • missing=:error: masked dyads are refused; :face uses their stored face values.

A network with no ties has no scale α and returns NaN scores, as sna does.

Example

using SNA
star = network(4; directed=false)
add_edges!(star, [(1, 2), (1, 3), (1, 4)])
bonpow(star; exponent=0.2)
source
SNA.infocent — Function
infocent(net; cmode=:weak, rescale=false, diag=false, ignore_eval=true,
         attr=:weight, missing=:error) -> Vector{Float64}

Stephenson–Zelen information centrality: R sna::infocent. Information centrality is defined on undirected networks: a directed network is first symmetrized, with cmode=:weak (a tie in either direction, sna's default) or cmode=:strong (mutual ties only). Isolates score 0, and, as in sna, n in the formula counts every vertex, isolates included.

Example

using SNA
path = network(4; directed=false)
add_edges!(path, [(1, 2), (2, 3), (3, 4)])
infocent(path)
source

Graph centralization

SNA.centralization — Function
centralization(net, f; normalized=true, missing=:error, kwargs...) -> Float64
centralization(net, measure::Symbol; mode=:total, normalized=true, missing=:error) -> Float64

Freeman graph centralization of a vertex index: R sna::centralization,

C = Σᵢ (c_max − cᵢ) / C_max

where cᵢ = f(net; kwargs...) and C_max is the largest value of the numerator over all networks of the same size (sna's tmaxdev). Keyword arguments other than normalized and missing are passed to f, as R passes ... to FUN; the theoretical maximum follows the same cmode.

f is one of degreecent, betweenness, closeness, evcent or bonpow. Any other function taking (net; missing, kwargs...) works with normalized=false, which returns the raw deviation sum. The Symbol form accepts :degree, :betweenness, :closeness and :eigenvector, with mode = :total, :in or :out selecting the degree type.

A network too small for the maximum to be positive (for instance two vertices) gives NaN, as sna does.

missing=:error refuses a network with masked dyads; missing=:face is forwarded to f.

Example

using SNA
star = network(5; directed=false)
add_edges!(star, [(1, 2), (1, 3), (1, 4), (1, 5)])
centralization(star, degreecent)     # 1.0
centralization(star, betweenness)    # 1.0
source