This is a super helpful package, however there is a small inconsistency with outcome_base in prop_parity function.
To recreate the issue, taking outcome for Caucasian group only:
data("compas")
pred<-factor(compas$predicted[compas$ethnicity=="Caucasian"])
#converting outcome to binary
compas["Two_yr_Recidivism_01"]<- ifelse(compas$Two_yr_Recidivism=="yes",1,0)
ref<-factor(compas$Two_yr_Recidivism_01[compas$ethnicity=="Caucasian"])
#Ground Truth
caret::confusionMatrix(pred,ref,positive = "1")
Output:
Confusion Matrix and Statistics
Reference
Prediction 0 1
0 997 434
1 284 388
Accuracy : 0.6586
95% CI : (0.6379, 0.6789)
No Information Rate : 0.6091
P-Value [Acc > NIR] : 1.557e-06
Kappa : 0.2588
Mcnemar's Test P-Value : 2.688e-08
**Sensitivity : 0.4720**
Specificity : 0.7783
Pos Pred Value : 0.5774
Neg Pred Value : 0.6967
Prevalence : 0.3909
Detection Rate : 0.1845
**Detection Prevalence : 0.3195**
Balanced Accuracy : 0.6252
**'Positive' Class : 1**
Note that the sensitivity for Caucasian group is 0.47 and detection prevalence (or proportional parity) is 0.3195
equal_odds(data = compas,
outcome = 'Two_yr_Recidivism_01',
probs = 'probability',
group = 'ethnicity',
cutoff = 0.5,
base = 'Caucasian',outcome_base = "1")$Metric
Output:
Caucasian African_American Asian Hispanic Native_American Other
Sensitivity 0.4720195 0.7525587 0.2500000 0.4656085 0.600000 0.4193548
Equalized odds 1.0000000 1.5943383 0.5296392 0.9864179 1.271134 0.8884270
Group size 2103.0000000 3175.0000000 31.0000000 509.0000000 11.000000 343.0000000
Sensitivity is correct, i.e 0.47 for Caucasian. Note however that outcome_base = "1". Changing this to 1, because this is the positive class to create confusion matrix.
Using same outcome_base to get prop_parity:
prop_parity(data = compas,
outcome = 'Two_yr_Recidivism_01',
probs = 'probability',
group = 'ethnicity',
cutoff = 0.5,
base = 'Caucasian',outcome_base = "1")$Metric
Output:
Caucasian African_American Asian Hispanic Native_American Other
Proportion 0.6804565 0.4081890 0.8709677 0.7072692 0.5454545 0.7521866
Proportional Parity 1.0000000 0.5998752 1.2799757 1.0394039 0.8016009 1.1054147
Group size 2103.0000000 3175.0000000 31.0000000 509.0000000 11.0000000 343.0000000
You can see that the proportion (i.e.(TP + FP) / (TP + FP + TN + FN)) is incorrectly calculated as 0.68. This is because you relevel the outcomes and predictions and then subtract 1 after converting this to numeric, which in a way reverses the class.
So, to get the correct result, outcome_base should be set to negative class in this function alone.
prop_parity(data = compas,
outcome = 'Two_yr_Recidivism_01',
probs = 'probability',
group = 'ethnicity',
cutoff = 0.5,
base = 'Caucasian',outcome_base = "0")$Metric
Caucasian African_American Asian Hispanic Native_American Other
Proportion 0.3195435 0.591811 0.1290323 0.2927308 0.4545455 0.2478134
Proportional Parity 1.0000000 1.852051 0.4038018 0.9160907 1.4224838 0.7755232
Group size 2103.0000000 3175.000000 31.0000000 509.0000000 11.0000000 343.0000000
For the sake of consistency with other parity functions, I'd recommend using Detection Prevalence from confusion matriculates to calculate this metric.
Thank you!