DRrank
DRrank is a Python library to implement the Empirical Bayes ranking scheme developed in Kline, Rose, and Walters (2023).
Installation:
The package uses the Gurobi optimizer. To use DRrank you must first install Gurobi and acquire a license. More guidance is available from Gurobi here). Gurobi offers a variety of free licenses for academic use. For more information, see the following page.
After having successfully set up Gurobipy, install DRrank via pip:
pip install drrank
Usage
To compute rankings, provide the fit function with a matrix $P$ of posterior estimates of the probability observation i's latent measure (e.g., bias, quality, etc.) exceeds unit j's. That is, each element of this matrix takes the form:
$\pi_{ij} = Pr(\theta_i > \theta_j | Y_i = y_i, Y_j = y_j)$
DRrank expects these probabilities to satisfy $\pi_{ij} = 1-\pi_{ji}$.
There are two ways to use DRrank.
First, one can supply a parameter $\lambda \in [0,1]$, which corresponds to the user's value of correctly ranking pairs of units relative to the costs of misclassifying them. $\lambda=1$ implies correct and incorrect rankings are valued equally, while $\lambda=0$ implies correct rankings are not valued at all. In pairwise comparisons between units, it is optimal to assign unit $i$ a higher grade than unit $j$ when $\pi_{ij} > 1/(1+\lambda)$, which implies $\lambda$ also determines the minimum level of posterior certainty required to rank units pairwise.
from drrank import fit
from simul_pij import simul_data
# Simulate data
p_ij = simul_data(size = 25)
# Fit the report card function
results = fit(p_ij, lamb = 0.25, DR = None)
The results ojbect contains the row index of $P$, the assigned grades, and the Condorcet rank (i.e., grade under $\lambda=1$).
| obs_idx | grades_lamb0.25 | condorcet_rank |
|---|---|---|
| 1 | 1 | 5 |
| 2 | 1 | 2 |
| 3 | 1 | 13 |
| 4 | 1 | 4 |
| 5 | 1 | 9 |
We also provide functionality to compute results for a list of values $\lambda$ in parallel:
import numpy as np
from drrank import fit_multiple
# Try different values of Lambda
results_l = fit_multiple(p_ij, np.arange(0, 0.9, 0.01))
Second, one can ask DRrank to compute grades that maximize Kendall (1938)'s $\tau$, a measure of the rank correlation between units' latent rankings and assigned grades, subject to a constraint on the expected share of pairwise units incorrectly classified, which we refer to as the Discordance Rate (DR).
# Fit the report card function
results = fit(p_ij, lamb = None, DR = 0.05)
Metadata
Release files for drrank 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drrank-0.0.1.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drrank-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.6 kB
Release files / drrank-0.0.1.tar.gz
| Download URL | drrank-0.0.1.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb6efba7f958ed5aaf958cca3b19f561d9707ec5ffb6e3e8cfc7d0d8fe220a48
|
|
BLAKE2b-256 checksum How to use checksums |
6f827d533f30764e4e9033fc1ab24d648daed45d8ba78098b7c5ed271e5ad5e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.12
|
Release files / drrank-0.0.1-py3-none-any.whl
| Download URL | drrank-0.0.1-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86f1b818f0ed7360ad0678b689d28baf836b1e3cf3ca85dce43b946adf8a8d2c
|
|
BLAKE2b-256 checksum How to use checksums |
92e75ec4b9d14bc773082c6a955ca8a89448a4d462ccc787346acab19f8b5b07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.12
|