feat: add pagerank to `network_summary()`

This commit is contained in:
Martin Chan 2023-08-16 12:35:43 +01:00
Родитель 17c85c1642
Коммит 5ce82b438c
3 изменённых файлов: 18 добавлений и 9 удалений

Просмотреть файл

@ -7,6 +7,8 @@ Updates to `network_p2p()`, with breaking changes to the argument, addressing is
- Improved consistency and intuitiveness of the API, with `style` argument now controlling the network plotting mechanism and `return` argument controlling whether plots are generated interactively or saved as PDF - Improved consistency and intuitiveness of the API, with `style` argument now controlling the network plotting mechanism and `return` argument controlling whether plots are generated interactively or saved as PDF
- Added a large number of community detection algorithms from `igraph` - Added a large number of community detection algorithms from `igraph`
`network_summary()` adds the ability to return pagerank.
This version also includes some minor dependency maintenance done to `create_dt()`. This version also includes some minor dependency maintenance done to `create_dt()`.
# wpa 1.8.1 # wpa 1.8.1

Просмотреть файл

@ -30,6 +30,7 @@
#' given node. #' given node.
#' - degree: number of connections linked to a node. #' - degree: number of connections linked to a node.
#' - eigenvector: a measure of the influence a node has on a network. #' - eigenvector: a measure of the influence a node has on a network.
#' - pagerank: calculates the PageRank for the specified vertices.
#' Please refer to the igraph package documentation for the detailed technical #' Please refer to the igraph package documentation for the detailed technical
#' definition. #' definition.
#' #'
@ -44,7 +45,7 @@
#' #'
#' @examples #' @examples
#' # Simulate a p2p network #' # Simulate a p2p network
#' p2p_data <- p2p_data_sim() #' p2p_data <- p2p_data_sim(size = 100)
#' g <- network_p2p(data = p2p_data, return = "network") #' g <- network_p2p(data = p2p_data, return = "network")
#' #'
#' # Return summary table #' # Return summary table
@ -67,7 +68,6 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
## NULL variables ## NULL variables
node_id <- NULL node_id <- NULL
## Calculate summary table ## Calculate summary table
sum_tb <- sum_tb <-
dplyr::tibble( dplyr::tibble(
@ -75,7 +75,8 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
betweenness = igraph::centralization.betweenness(graph = graph)$res, betweenness = igraph::centralization.betweenness(graph = graph)$res,
closeness = igraph::centralization.closeness(graph = graph)$res, closeness = igraph::centralization.closeness(graph = graph)$res,
degree = igraph::centralization.degree(graph = graph)$res, degree = igraph::centralization.degree(graph = graph)$res,
eigenvector = igraph::centralization.evcent(graph = graph)$vector eigenvector = igraph::centralization.evcent(graph = graph)$vector,
pagerank = igraph::page_rank(graph)$vector
) )
if(!is.null(hrvar)){ if(!is.null(hrvar)){
@ -99,11 +100,11 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
graph = graph, graph = graph,
name = "betweenness", name = "betweenness",
value = sum_tb$betweenness value = sum_tb$betweenness
) %>% ) %>%
igraph::set_vertex_attr( igraph::set_vertex_attr(
name = "closeness", name = "closeness",
value = sum_tb$closeness value = sum_tb$closeness
) %>% ) %>%
igraph::set_vertex_attr( igraph::set_vertex_attr(
name = "degree", name = "degree",
value = sum_tb$degree value = sum_tb$degree
@ -111,6 +112,10 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
igraph::set_vertex_attr( igraph::set_vertex_attr(
name = "eigenvector", name = "eigenvector",
value = sum_tb$eigenvector value = sum_tb$eigenvector
) %>%
igraph::set_vertex_attr(
name = "pagerank",
value = sum_tb$pagerank
) )
graph graph
@ -134,7 +139,8 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
"betweenness", "betweenness",
"closeness", "closeness",
"degree", "degree",
"eigenvector" "eigenvector",
"pagerank"
) )
) )
} }
@ -148,7 +154,8 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
"betweenness: number of shortest paths going through a node.", "betweenness: number of shortest paths going through a node.",
"closeness: number of steps required to access every other node from a given node.", "closeness: number of steps required to access every other node from a given node.",
"degree: number of connections linked to a node.", "degree: number of connections linked to a node.",
"eigenvector: a measure of the influence a node has on a network." "eigenvector: a measure of the influence a node has on a network.",
"pagerank: a measure of the relative importance of nodes based on linked nodes."
), ),
collapse = "\n" collapse = "\n"
) )
@ -162,4 +169,3 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
} }

Просмотреть файл

@ -31,6 +31,7 @@ statistics include:
given node. given node.
\item degree: number of connections linked to a node. \item degree: number of connections linked to a node.
\item eigenvector: a measure of the influence a node has on a network. \item eigenvector: a measure of the influence a node has on a network.
\item pagerank: calculates the PageRank for the specified vertices.
Please refer to the igraph package documentation for the detailed technical Please refer to the igraph package documentation for the detailed technical
definition. definition.
} }
@ -49,7 +50,7 @@ the centralization functions in 'igraph'.
} }
\examples{ \examples{
# Simulate a p2p network # Simulate a p2p network
p2p_data <- p2p_data_sim() p2p_data <- p2p_data_sim(size = 100)
g <- network_p2p(data = p2p_data, return = "network") g <- network_p2p(data = p2p_data, return = "network")
# Return summary table # Return summary table