Package 'DirectedClustering'

Title: Directed Weighted Clustering Coefficient
Description: Allows the computation of clustering coefficients for directed and weighted networks by using different approaches. It allows to compute clustering coefficients that are not present in 'igraph' package. A description of clustering coefficients can be found in "Directed clustering in weighted networks: a new perspective", Clemente, G.P., Grassi, R. (2017), <doi:10.1016/j.chaos.2017.12.007>.
Authors: Gian Paolo Clemente [cre, aut] , Rosanna Grassi [ctb]
Maintainer: Gian Paolo Clemente <[email protected]>
License: GPL-3 | file LICENSE
Version: 1.0.0
Built: 2025-02-21 05:15:03 UTC
Source: https://github.com/gianpaoloclemente/directedclustering

Help Index


Alternative Clustering Coefficients for Directed/Undirected and Weighted Networks

Description

The DirectedClustering R package presented here includes an enhanced R implementation of Local and Global (average) Clustering Coefficients for Directed/Undirected and Unweighted/Weighted Networks.
Functions are based on Barrat et al. (2004) and Onnela et al. (2005) coefficients when the network is undirected, while it is based on Fagiolo (2007) and Clemente and Grassi (2018) proposals when the network is directed. In the directed case, different components of directed clustering coefficient are also considered.

Details of alternative coefficients computed by DirectedClustering R package can be found in Clemente, Grassi (2018).

Please report any issue arising or bug in the code to [email protected].

Note

This package and the functions herein are provided as is, without any guarantee regarding the accuracy of calculations. The authors disclaim any liability arising by any losses due to direct and indirect use of this package.

Author(s)

Gian Paolo Clemente, [email protected], Rosanna Grassi, [email protected]

References

Clemente, G.P. and Grassi, R. (2018) Directed clustering in weighted networks: a new perspective, Chaos, Solitons and Fractals, 107,26–38.


Clustering Coefficient for Directed/Undirected and Weighted Networks

Description

Compute Local and Global (average) Clustering Coefficients for Directed/Undirected and Unweighted/Weighted Networks.

Usage

ClustBCG(mat, type = "undirected", isolates = "zero")

Arguments

mat

A weighted adjacency matrix.

type

The type of clustering coefficient to calculate. Possible values are: "undirected" (default) or "directed".

isolates

Character scalar, defines how to treat vertices with degree zero and one. If "NaN", their local transitivity is reported as NaN and they are not included in the averaging. If "zero", their transitivity is reported as 0 and they are included in the averaging. Default is "zero".

Details

Formulas are based on Barrat et al. (2004) for undirected networks, and on Clemente and Grassi (2018) for directed networks.

In the directed case, different components of the directed clustering coefficient are also provided.

The function computes the Barrat et al. (2004) coefficient for a weighted and undirected network. For a directed network, the Clemente and Grassi (2018) formula is used. In case of unweighted and undirected graphs, the classical local clustering coefficient (Watts and Strogatz) is provided. Local clustering coefficients are computed for each node, and the global coefficient is the average of these local coefficients. These coefficients do not work for graphs with multiple or loop edges, hence loops are removed.

Value

A list with the following components:

LocalCC

Local clustering coefficients for undirected networks

GlobalCC

Global clustering coefficient for undirected networks

cycleCC

Local Cycle clustering coefficients for directed networks

middlemanCC

Local Middleman clustering coefficients for directed networks

inCC

Local In clustering coefficients for directed networks

outCC

Local Out clustering coefficients for directed networks

totalCC

Local Total clustering coefficients for directed networks

GlobalcycleCC

Global Cycle clustering coefficient for directed networks

GlobalmiddlemanCC

Global Middleman clustering coefficient for directed networks

GlobalinCC

Global In clustering coefficient for directed networks

GlobaloutCC

Global Out clustering coefficient for directed networks

GlobaltotalCC

Global Total clustering coefficient for directed networks

Author(s)

Gian Paolo Clemente, [email protected]

References

Barrat, A., Barthelemy, M., Pastor-Satorras, R., & Vespignani, A. (2004). The architecture of complex weighted networks. Proceedings of the National Academy of Sciences, USA, 101, 3747.

Clemente, G.P., & Grassi, R. (2018). Directed clustering in weighted networks: a new perspective. Chaos, Solitons and Fractals, 107, 26–38.

Watts, D.J., & Strogatz, S.H. (1998). Collective dynamics of 'small-world' networks. Nature, 393, 440-442.

Examples

if (requireNamespace("igraph", quietly = TRUE)) {
  library(igraph)
  # Generate a weighted and undirected graph
  gsim <- sample_gnp(50, 0.5, directed = FALSE, loops = FALSE)
  PESI <- runif(length(E(gsim)), 0, 1)
  E(gsim)$weight <- PESI
  A <- as_adjacency_matrix(gsim, sparse = FALSE, attr = "weight")
  BarratClust <- ClustBCG(A, "undirected")
  check <- sum(BarratClust$LocalCC - transitivity(gsim, "weighted"))

  # Generate a weighted and directed graph
  gsim <- sample_gnp(50, 0.5, directed = TRUE, loops = FALSE)
  PESI <- runif(length(E(gsim)), 0, 1)
  E(gsim)$weight <- PESI
  A <- as_adjacency_matrix(gsim, sparse = FALSE, attr = "weight")
  CGClust <- ClustBCG(A, "directed")
} else {
  cat("Please install the 'igraph' package to run this example.\n")
}

Clustering Coefficients for Directed/Undirected and Weighted Networks

Description

This function computes both Local and Global (average) Clustering Coefficients for either Directed/Undirected and Unweighted/Weighted Networks. The formulas are based on Onnela et al. (2005) for undirected networks, and on Fagiolo (2007) for directed networks.

Usage

ClustF(mat, type = "undirected", isolates = "zero", norm = 1)

Arguments

mat

A weighted adjacency matrix. If weights are greater than one, a normalization is provided by dividing each weight by the maximum weight observed.

type

The type of clustering coefficient to calculate. Possible values are: "undirected" (default) or "directed".

isolates

Character scalar, defines how to treat vertices with degree zero and one. If "NaN", their local transitivity is reported as NaN and they are not included in the averaging. If "zero", their transitivity is reported as 0 and they are included in the averaging. Default is "zero".

norm

If it is 1 (default), the link's weights are normalized by dividing by the maximum observed weight (as proposed by Fagiolo). If it is 0, weights are not normalized. Weights are always normalized when the maximum weight is greater than zero, ensuring that the clustering coefficient ranges between 0 and 1.

Details

In the directed case, different components of the directed clustering coefficient are also considered.

The function computes Onnela et al.'s (2005) formula for weighted and undirected networks. For directed networks, Fagiolo's (2007) formula is used. In the case of unweighted and undirected graphs, the classical local clustering coefficient (Watts and Strogatz) is provided. Local coefficients are computed for each node, and the global coefficient is the average of these local coefficients. These coefficients do not work for graphs with multiple or loop edges, so loops are removed.

Value

A list with the following components:

LocalCC

Local clustering coefficients for undirected networks

GlobalCC

Global clustering coefficient for undirected networks

cycleCC

Local Cycle clustering coefficients for directed networks

middlemanCC

Local Middleman clustering coefficients for directed networks

inCC

Local In clustering coefficients for directed networks

outCC

Local Out clustering coefficients for directed networks

totalCC

Local Total clustering coefficients for directed networks

GlobalcycleCC

Global Cycle clustering coefficient for directed networks

GlobalmiddlemanCC

Global Middleman clustering coefficient for directed networks

GlobalinCC

Global In clustering coefficient for directed networks

GlobaloutCC

Global Out clustering coefficient for directed networks

GlobaltotalCC

Global Total clustering coefficient for directed networks

Author(s)

Gian Paolo Clemente, [email protected]

References

Fagiolo, G. (2007). Clustering in complex directed networks. Physical Review E, 76(2).

Onnela, J.P., Saramaki, J., Kertsz, J., & Kaski, K. (2005). Intensity and coherence of motifs in weighted complex networks. Physical Review E, 71(6).

Watts, D.J., & Strogatz, S.H. (1998). Collective dynamics of 'small-world' networks. Nature, 393, 440-442.

Examples

if (requireNamespace("igraph", quietly = TRUE)) {
  library(igraph)
  # Generate a weighted and undirected graph
  gsim <- sample_gnp(50, 0.5, directed = FALSE, loops = FALSE)
  PESI <- runif(length(E(gsim)), 0, 1)
  E(gsim)$weight <- PESI
  A <- as_adjacency_matrix(gsim, sparse = FALSE, attr = "weight")
  OnnelaClust <- ClustF(A, "undirected")

  # Generate a weighted and directed graph
  gsim <- sample_gnp(50, 0.5, directed = TRUE, loops = FALSE)
  PESI <- runif(length(E(gsim)), 0, 1)
  E(gsim)$weight <- PESI
  A <- as_adjacency_matrix(gsim, sparse = FALSE, attr = "weight")
  FagioloClust <- ClustF(A, "directed")
} else {
  cat("Please install the 'igraph' package to run this example.\n")
}