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
- 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()`.
# wpa 1.8.1

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

@ -30,6 +30,7 @@
#' given node.
#' - degree: number of connections linked to a node.
#' - 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
#' definition.
#'
@ -44,7 +45,7 @@
#'
#' @examples
#' # Simulate a p2p network
#' p2p_data <- p2p_data_sim()
#' p2p_data <- p2p_data_sim(size = 100)
#' g <- network_p2p(data = p2p_data, return = "network")
#'
#' # Return summary table
@ -67,7 +68,6 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
## NULL variables
node_id <- NULL
## Calculate summary table
sum_tb <-
dplyr::tibble(
@ -75,7 +75,8 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
betweenness = igraph::centralization.betweenness(graph = graph)$res,
closeness = igraph::centralization.closeness(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)){
@ -111,6 +112,10 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
igraph::set_vertex_attr(
name = "eigenvector",
value = sum_tb$eigenvector
) %>%
igraph::set_vertex_attr(
name = "pagerank",
value = sum_tb$pagerank
)
graph
@ -134,7 +139,8 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
"betweenness",
"closeness",
"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.",
"closeness: number of steps required to access every other node from a given 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"
)
@ -162,4 +169,3 @@ network_summary <- function(graph, hrvar = NULL, return = "table"){
}

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

@ -31,6 +31,7 @@ statistics include:
given node.
\item degree: number of connections linked to a node.
\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
definition.
}
@ -49,7 +50,7 @@ the centralization functions in 'igraph'.
}
\examples{
# Simulate a p2p network
p2p_data <- p2p_data_sim()
p2p_data <- p2p_data_sim(size = 100)
g <- network_p2p(data = p2p_data, return = "network")
# Return summary table