# Install and load igraph
#install.packages("igraph")
library(igraph)
## Warning: package 'igraph' was built under R version 4.5.3
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
# Example: a simple directed graph
# edges: 1→3, 2→3, 3→4, 4→5, 5→1
edges <- c(1,3, 2,3, 3,4, 4,5, 5,1)
# Create graph
g <- make_graph(edges, directed = TRUE)
# Represent graph using adjacency matrix
A <- as_adjacency_matrix(g, sparse = FALSE)
print(A)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 1 0 0
## [2,] 0 0 1 0 0
## [3,] 0 0 0 1 0
## [4,] 0 0 0 0 1
## [5,] 1 0 0 0 0
# Plot the graph
plot(
g,
vertex.size = 30,
vertex.color = "lightblue",
vertex.label = c(1,2,3,4,5),
edge.arrow.size = 0.6
)

# Calculate authority and hub scores
hits_scores <- hits_scores(g)
# View results
print("Authority scores:")
## [1] "Authority scores:"
print(hits_scores$authority)
## [1] 7.850462e-17 0.000000e+00 1.000000e+00 7.850462e-17 1.177569e-16
print("Hub scores:")
## [1] "Hub scores:"
print(hits_scores$hub)
## [1] 1.000000e+00 1.000000e+00 1.570092e-16 2.355139e-16 1.570092e-16