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")
}
Run the code above in your browser using DataLab