{"id":16578421,"url":"https://github.com/schochastics/netrankr","last_synced_at":"2025-04-06T03:07:45.809Z","repository":{"id":41827335,"uuid":"90736378","full_name":"schochastics/netrankr","owner":"schochastics","description":"An R package for network centrality","archived":false,"fork":false,"pushed_at":"2025-02-05T19:36:25.000Z","size":25375,"stargazers_count":48,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-30T00:09:18.046Z","etag":null,"topics":["network-analysis","network-centrality","r-package"],"latest_commit_sha":null,"homepage":"https://schochastics.github.io/netrankr/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schochastics.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-09T11:06:32.000Z","updated_at":"2025-03-22T11:11:16.000Z","dependencies_parsed_at":"2023-01-29T22:45:38.803Z","dependency_job_id":"1c38d3ec-a606-4914-9f5e-b46ca8c84424","html_url":"https://github.com/schochastics/netrankr","commit_stats":{"total_commits":446,"total_committers":5,"mean_commits":89.2,"dds":"0.32959641255605376","last_synced_commit":"d59c7ca898e07da4227be724ba2cf685849dd89f"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fnetrankr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fnetrankr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fnetrankr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fnetrankr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schochastics","download_url":"https://codeload.github.com/schochastics/netrankr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["network-analysis","network-centrality","r-package"],"created_at":"2024-10-11T22:14:20.216Z","updated_at":"2025-04-06T03:07:45.793Z","avatar_url":"https://github.com/schochastics.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n# netrankr \u003cimg src=\"man/figures/logo.png\" align=\"right\"/\u003e\n[![R-CMD-check](https://github.com/schochastics/netrankr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/schochastics/netrankr/actions/workflows/R-CMD-check.yaml)\n[![CRAN Status Badge](https://www.r-pkg.org/badges/version/netrankr)](https://cran.r-project.org/package=netrankr)\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/netrankr)](https://CRAN.R-project.org/package=netrankr) \n[![Codecov test coverage](https://codecov.io/gh/schochastics/netrankr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/schochastics/netrankr?branch=main)\n[![JOSS](https://joss.theoj.org/papers/10.21105/joss.04563/status.svg)](https://doi.org/10.21105/joss.04563)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7109041.svg)](https://doi.org/10.5281/zenodo.7109041)\n\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(\n    collapse = TRUE,\n    fig.align = \"center\",\n    out.width = \"80%\",\n    comment = \"#\u003e\",\n    fig.path = \"man/figures/README-\",\n    echo = TRUE,\n    warning = FALSE,\n    message = FALSE\n)\n```\n\n## Overview \n\nThe literature is flooded with centrality indices and new ones are introduced \non a regular basis. Although there exist several theoretical and empirical guidelines \non when to use certain indices, there still exists plenty of ambiguity in the concept \nof network centrality. To date, network centrality is nothing more than applying indices\nto a network:\n\n![](man/figures/flow_old.png)\n\nThe only degree of freedom is the choice of index. The package comes with an Rstudio addin (`index_builder()`),\nwhich allows to build or choose from more than 20 different indices. Blindly (ab)using\nthis function is highly discouraged!\n\nThe `netrankr` package is based on the idea that centrality is more than a \nconglomeration of indices. Decomposing them in a series of microsteps offers \nthe posibility to gradually add ideas about centrality, without succumbing to\ntrial-and-error approaches. Further, it allows for alternative assessment methods\nwhich can be more general than the index-driven approach:\n\n![](man/figures/flow_new.png)\n\nThe new approach is centered around the concept of *positions*, which are defined as \nthe relations and potential attributes of a node in a network. The aggregation\nof the relations leads to the definition of indices. However, positions can also\nbe compared via *positional dominance*, leading to partial centrality rankings and\nthe option to calculate probabilistic centrality rankings.\n\nFor a more detailed theoretical background, consult the [Literature](#literature) \nat the end of this page.\n\n________________________________________________________________________________\n\n## Installation\n\nTo install from CRAN: \n```{r install_cran, eval=FALSE}\ninstall.packages(\"netrankr\")\n```\n\nTo install the developer version from github:\n```{r install_git, eval=FALSE}\n# install.packages(\"remotes\")\nremotes::install_github(\"schochastics/netrankr\")\n```\n\n________________________________________________________________________________\n\n## Simple Example\n\nThis example briefly explains some of the functionality of the package and the \ndifference to an index driven approach. For a more realistic application see \nthe use case vignette. \n\nWe work with the following small graph.\n```{r example_graph, warning=FALSE,message=FALSE}\nlibrary(igraph)\nlibrary(netrankr)\n\ndata(\"dbces11\")\ng \u003c- dbces11\n```\n\n```{r dbces_neutral, echo=FALSE}\nlibrary(ggraph)\nV(g)$name \u003c- as.character(1:11)\nggraph(g, \"stress\") +\n    geom_edge_link0(edge_colour = \"grey66\") +\n    geom_node_point(shape = 21, fill = \"grey25\", size = 8) +\n    geom_node_text(aes(label = name), col = \"white\") +\n    theme_graph()\n```\n\nSay we are interested in the most central node of the graph and simply compute some \nstandard centrality scores with the `igraph` package. Defining centrality indices\nin the `netrankr` package is explained in the centrality indices vignette.\n```{r cent,warning=FALSE}\ncent_scores \u003c- data.frame(\n    degree = degree(g),\n    betweenness = round(betweenness(g), 4),\n    closeness = round(closeness(g), 4),\n    eigenvector = round(eigen_centrality(g)$vector, 4),\n    subgraph = round(subgraph_centrality(g), 4)\n)\n\n# What are the most central nodes for each index?\napply(cent_scores, 2, which.max)\n```\n\n```{r dbces_color, echo=FALSE}\nV(g)$col \u003c- \"none\"\nV(g)$col[apply(cent_scores, 2, which.max)] \u003c- names(apply(cent_scores, 2, which.max))\n\nV(g)$lab \u003c- \"\"\nV(g)$lab[apply(cent_scores, 2, which.max)] \u003c- stringr::str_to_upper(stringr::str_extract(names(apply(cent_scores, 2, which.max)), \"^[a-z]\"))\nggraph(g, \"stress\") +\n    geom_edge_link0(edge_colour = \"grey66\") +\n    geom_node_point(aes(fill = col), shape = 21, size = 8) +\n    geom_node_text(aes(label = lab), col = \"white\") +\n    scale_fill_manual(values = c(\"#1874CD\", \"#CD2626\", \"#EEB422\", \"#9A32CD\", \"#4D4D4D\", \"#EE30A7\")) +\n    theme_graph() +\n    theme(legend.position = \"none\")\n```\n\nAs you can see, each index assigns the highest value to a different vertex.\n\nA more general assessment starts by calculating the neighborhood inclusion preorder.\n```{r ex_ni}\nP \u003c- neighborhood_inclusion(g)\nP\n```\n[Schoch \u0026 Brandes (2016)](https://doi.org/10.1017/S0956792516000401) showed that\n`P[u,v]=1` implies that u is less central than v for \ncentrality indices which are defined via specific path algebras. These include\nmany of the well-known measures like closeness (and variants), betweenness (and variants)\nas well as many walk-based indices (eigenvector and subgraph centrality, total communicability,...).\n\nNeighborhood-inclusion defines a partial ranking on the set of nodes. Each ranking \nthat is in accordance with this partial ranking yields a proper centrality ranking.\nEach of these ranking can thus potentially be the outcome of a centrality index.  \n\nUsing rank intervals, we can examine the minimal and maximal possible rank of each node.\nThe bigger the intervals are, the more freedom exists for indices to rank nodes differently.\n```{r partial}\nplot(rank_intervals(P), cent_scores = cent_scores, ties.method = \"average\")\n```\n\nThe potential ranks of nodes are not uniformly distributed in the intervals. To get\nthe exact probabilities, the function `exact_rank_prob()` can be used.\n```{r ex_p}\nres \u003c- exact_rank_prob(P)\nres\n```\nFor the graph `g` we can therefore come up with\n`r format(res$lin.ext,big.mark = \",\")` indices that would rank the nodes differently.  \n\n`rank.prob` contains the probabilities for each node to occupy a certain rank. \nFor instance, the probability for each node to be the most central one is as follows.\n```{r most_central}\nround(res$rank.prob[, 11], 2)\n```\n\n`relative.rank` contains the relative rank probabilities. An entry `relative.rank[u,v]`\nindicates how likely it is that `v` is more central than `u`.\n```{r rel_rank}\n# How likely is it, that 6 is more central than 3?\nround(res$relative.rank[3, 6], 2)\n```\n\n`expected.ranks` contains the expected centrality ranks for all nodes. They are \nderived on the basis of `rank.prob`.\n```{r exp_rank}\nround(res$expected.rank, 2)\n```\nThe higher the value, the more central a node is expected to be.\n\n**Note**: The set of rankings grows exponentially in the number of nodes and the exact \ncalculation becomes infeasible quite quickly and approximations need to be used.\nCheck the benchmark results for guidelines.\n\n________________________________________________________________________________\n\n## Theoretical Background {#literature}\n\n`netrankr` is based on a series of papers that appeared in recent years. If you \nwant to learn more about the theoretical background of the package, \nconsult the following literature:\n\n\u003e Schoch, David. (2018). Centrality without Indices: Partial rankings and rank\nProbabilities in networks. *Social Networks*, **54**, 50-60.([link](https://doi.org/10.1016/j.socnet.2017.12.003))\n\n\u003e Schoch, David \u0026 Valente, Thomas W., \u0026 Brandes, Ulrik. (2017). Correlations among centrality indices\nand a class of uniquely ranked graphs. *Social Networks*, **50**, 46-54.([link](https://doi.org/10.1016/j.socnet.2017.03.010))\n\n\u003e Schoch, David \u0026 Brandes, Ulrik. (2016). Re-conceptualizing centrality in social networks.\n*European Journal of Appplied Mathematics*, **27**(6), 971–985.\n([link](https://doi.org/10.1017/S0956792516000401))\n\n\u003e Brandes, Ulrik. (2016). Network Positions.\n*Methodological Innovations*, **9**, 2059799116630650.\n([link](https://dx.doi.org/10.1177/2059799116630650))\n\n## Code of Conduct\n\nPlease note that the netrankr project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschochastics%2Fnetrankr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschochastics%2Fnetrankr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschochastics%2Fnetrankr/lists"}