Targeting Evaluations#

from cider.datastore import DataStore
from cider.targeting import Targeting

Set up the configuration file and load some targeting simulation data, using the datastore object.

# This path should point to your cider installation, where configs and data for this demo are located.
from pathlib import Path
cider_installation_directory = Path('../../cider')

datastore = DataStore(config_file_path_string= cider_installation_directory / 'configs' / 'config_quickstart.yml')
targeting = Targeting(datastore=datastore)

Create a table that compares targeting methods to a ground truth poverty measure. Three threshold-agnostic targeting metrics will be calculated: Pearson correlation (between ground truth and proxies), Spearman correlation, and a threshold-agnostic Area Under the Reciever Operating Characteristic Curve Score (AUC). Additionally, provide percentile targeting thresholds for ground truth and proxy to obtain four threshold-specific targeting metrics: accuracy, precision, recall, and threshold-specific AUC. As with all calculations in this module, the table can be calculated with or without sample weights.

targeting.targeting_table('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], 50, 20)
Targeting Method Pearson Spearman AUC (Threshold-Agnostic) Accuracy Precision Recall AUC (Threshold-Specific)
0 proxy1 0.853370 0.856880 0.882319 0.700 1.000 0.400 0.925204
1 proxy2 0.816323 0.818275 0.869501 0.698 0.995 0.398 0.921336
2 proxy3 0.775243 0.772671 0.846071 0.688 0.970 0.388 0.886284
3 proxy4 0.731196 0.724984 0.817799 0.680 0.950 0.380 0.866024

Draw threshold-agnostic receiver operatoring characteristic (ROC) curves and precision-recall curves. Threshold-agnostic ROC curves are drawn by taking a grid matched targeting thresholds (that is, targeting K% of the population according to a proxy and the same K% of the population according to the ground-truth, for a krid of K between 0 and 100), and calculating the false positive rate and true positive rate of the targeting method for each point in the grid. Threshold-agnostic precision-reccall curves are calculated in the same way, so precision and recall are balanced by construction.

targeting.roc_curves('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], p=None, weighted=False)
targeting.precision_recall_curves('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], p=None, weighted=False)
../_images/87598737ac4454d1a0f20533c22da6eb040b970020023848313229a5fb240db0.png ../_images/ba1056d7bcb7c86625496fdf93c88cca61a3092f413a1691eb14db109a062932.png

Draw threshold-specific ROC curves and precision-recall curves. Threshold-specific ROC curves are calculated by holding the share of the population targeted according to the ground-truth measure constant, and varying the share of the population targeted on the proxy measure to obtain false positive and true positive rate trade-offs.

targeting.roc_curves('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], p=50, weighted=False)
targeting.precision_recall_curves('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], p=50, weighted=False)
../_images/228f12239cc16183e099afd9d3109989bd4a5ca97041dee75016d4ec69809166.png ../_images/145650c79c5477ac5672a6a53833dc4778ed80d51b3459ce4a27ec779ce92657.png

Provide a budget (provided as the level of benefits assigned to each individual UBI program, in the same units as the ground truth poverty measure) to draw social welfare curves for a set of targeting methods. Individual welfare is assumed to be a convex function of pre-program poverty and benefits assigned. Generate a table with the share of population targeted and corresponding transfer size that optimizes social welfare for each proxy poverty measure that could be used for targeting.

targeting.utility_curves('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], .01, weighted=False)
targeting.utility_table('consumption', ['proxy1', 'proxy2', 'proxy3', 'proxy4'], .01, weighted=False)
../_images/df7204157563862d4ee46fe97536b4da8950340f54e6f7c5a2d0f5118e4bbd5d.png
Proxy Optimal Share of Population Targeted Maximum Utility Optimal Transfer Size
0 proxy1 26.255102 -1225.954439 0.038168
1 proxy2 9.081633 -817.080667 0.111111
2 proxy3 38.377551 -1606.065329 0.026110
3 proxy4 35.346939 -1582.812099 0.028329