---
title: "Partial Centrality"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{06 partial centrality}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

This vignette describes some methods to analyse partial rankings as obtained
from [neighborhood-inclusion](neighborhood_inclusion.html) or, more general,
[positional dominance](positional_dominance.html). More on the topic of
partial rankings can be found in the following literature.

> Schoch, David. (2018). Centrality without Indices: Partial rankings and rank
Probabilities in networks. *Social Networks*, **54**, 50-60.([link](https://doi.org/10.1016/j.socnet.2017.12.003))

> Patil, G.P. & Taillie, C. (2004). Multiple Indicators, partially ordered sets, 
and linear extensions: Multi-criterion ranking and prioritization. 
*Environmental and Ecological Statistics*, **11**, 199-228 ([link](https://link.springer.com/article/10.1023%2FB%3AEEST.0000027209.93218.d9))

```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.width=5,fig.align = 'center')
```

________________________________________________________________________________

## Rank intervals

```{r setup, warning=FALSE,message=FALSE}
library(netrankr)
library(igraph)
library(magrittr)
```

The function `rank_intervals()` is used to calculate the maximal and minimal possible 
rank for each node in any ranking that is in accordance with a given partial ranking. 

```{r pos_dom}
g <- graph.empty(n=11,directed = FALSE)
g <- add_edges(g,c(1,11,2,4,3,5,3,11,4,8,5,9,5,11,6,7,6,8,
                   6,10,6,11,7,9,7,10,7,11,8,9,8,10,9,10))
V(g)$name <- LETTERS[1:11]

#neighborhood inclusion 
P <- g %>% neighborhood_inclusion()

#without %>% operator:
# P <- neighborhood_inclusion(g)

rank_intervals(P)
```

The package uses the convention, that higher numerical ranks correspond to top 
ranked position. The lowest possible rank is thus 1. The column `mid_point` 
should not be confused with the *expected rank* of nodes, which is calculated
with the function `exact_rank_prob()`. See [this](probabilistic_cent.html) vignette
for more details.  
\
Rank intervals are useful to assess the ambiguity of ranking nodes. The bigger
the intervals are, the more freedom exists, e.g. for centrality indices, to rank 
nodes differently.  
\
The intervals can be visualized with the function `plot_rank_intervals()`. Note
that the package `ggplot2` is required to use the function properly. The function 
takes a partial ranking as input and *not* already calculated rank intervals. 
These are calculated internally.

The function can take a data frame of centrality scores as an additional parameter 
`cent.df`. The ranks of each node for each index are then plotted within each interval.
Again, the higher the numerical rank the higher ranked the node is according to the index.

```{r vis_intervals_cent}

cent_scores <- data.frame(
   degree=degree(g),
   betweenness=round(betweenness(g),4),
   closeness=round(closeness(g),4),
   eigenvector=round(eigen_centrality(g)$vector,4))

plot_rank_intervals(P,cent.df = cent_scores)
```

A small jitter effect is added to the points to reduce over-plotting.  
\
Observe the inconsistency
of betweenness for node $C$. Betweenness centrality is, so far, the only index that does not
*strictly* preserve neighborhood-inclusion. That is, while
$$
N(u)\subseteq N[v] \text{ and } N(v)\not\subseteq N[u] \implies c(u)<c(v)
$$
holds for most indices, betweenness fails to fulfill this property.  
\
The intervals reduce to single points for [threshold graphs](threshold_graph.html), 
since all nodes are pairwise comparable by neighborhood-inclusion.
```{r tg_ri}
set.seed(123)
tg <- threshold_graph(20,0.2)

#neighborhood inclusion 
P <- tg %>% neighborhood_inclusion()

#without %>% operator:
# P <- neighborhood_inclusion(tg)
plot_rank_intervals(P)
```

The described betweenness inconsistancy is most evident for threshold graphs as shown in
the rank intervals below.

```{r tg_ri_cent}
cent_scores <- data.frame(
   degree=degree(tg),
   betweenness=round(betweenness(tg),4),
   closeness=round(closeness(tg),4),
   eigenvector=round(eigen_centrality(tg)$vector,4))


plot_rank_intervals(P,cent.df=cent_scores)
```
