calculate_centrality: Calculate Node Centrality in a Graph

calculate_centralityR Documentation

Calculate Node Centrality in a Graph

Description

This function computes the centrality of nodes in a graph using either degree centrality or betweenness centrality.

This function calculates the centrality of nodes in a given network graph based on either **degree centrality** or **betweenness centrality**.

Usage

calculate_centrality(graph, type = c("degree", "betweenness"))

calculate_centrality(graph, type = c("degree", "betweenness"))

Arguments

graph

An 'igraph' object representing the network.

type

A character string specifying the type of centrality to compute. Options are '"degree"' (default) or '"betweenness"'.

Details

- **Degree centrality** measures the number of direct connections a node has. - **Betweenness centrality** measures the number of shortest paths passing through a node, indicating its role as a bridge in the network. - The function uses 'igraph::degree()' for degree centrality and a custom approach for betweenness centrality using 'igraph::shortest_paths()'.

Value

A named vector of centrality values for each node in the graph.

A named numeric vector where names represent node IDs and values represent centrality scores.

Examples

## Not run: 
library(igraph)

# Create a sample graph
g <- make_ring(10)
V(g)$name <- paste0("Node", 1:10)

# Calculate degree centrality
degree_centrality <- calculate_centrality(g, type = "degree")
print(degree_centrality)

# Calculate betweenness centrality
betweenness_centrality <- calculate_centrality(g, type = "betweenness")
print(betweenness_centrality)

## End(Not run)


tidymass/metpath documentation built on June 1, 2025, 10:05 p.m.