Calculates confusion matrices for each subgroup

group_matrices(protected, probs, preds, cutoff)

Arguments

protected

vector containing protected variable

probs

character name of column with probabilities

preds

numeric, vector with predictions

cutoff

numeric cutoff for probabilities, default = 0.5

Value

group_matrices object It is a list with values:

  • subgroup

    • tp - number of true positives

    • fp - number of false positives

    • tn - number of true negatives

    • fn - number of false negatives

Examples

data("compas")

glm_compas <- glm(Two_yr_Recidivism~., data=compas, family=binomial(link="logit"))
y_prob <- glm_compas$fitted.values

y_numeric <- as.numeric(compas$Two_yr_Recidivism)-1

gm <- group_matrices(compas$Ethnicity,
                     y_prob,
                     y_numeric,
                     cutoff = list(Asian = 0.45,
                     African_American = 0.5,
                     Other = 0.5,
                     Hispanic = 0.5,
                     Caucasian = 0.4,
                     Native_American = 0.5))

gm
#> $African_American
#> $tp
#> [1] 1142
#> 
#> $fp
#> [1] 533
#> 
#> $tn
#> [1] 981
#> 
#> $fn
#> [1] 519
#> 
#> attr(,"class")
#> [1] "confusion_matrix"
#> 
#> $Asian
#> $tp
#> [1] 1
#> 
#> $fp
#> [1] 1
#> 
#> $tn
#> [1] 22
#> 
#> $fn
#> [1] 7
#> 
#> attr(,"class")
#> [1] "confusion_matrix"
#> 
#> $Caucasian
#> $tp
#> [1] 454
#> 
#> $fp
#> [1] 371
#> 
#> $tn
#> [1] 910
#> 
#> $fn
#> [1] 368
#> 
#> attr(,"class")
#> [1] "confusion_matrix"
#> 
#> $Hispanic
#> $tp
#> [1] 59
#> 
#> $fp
#> [1] 37
#> 
#> $tn
#> [1] 283
#> 
#> $fn
#> [1] 130
#> 
#> attr(,"class")
#> [1] "confusion_matrix"
#> 
#> $Native_American
#> $tp
#> [1] 3
#> 
#> $fp
#> [1] 1
#> 
#> $tn
#> [1] 5
#> 
#> $fn
#> [1] 2
#> 
#> attr(,"class")
#> [1] "confusion_matrix"
#> 
#> $Other
#> $tp
#> [1] 31
#> 
#> $fp
#> [1] 17
#> 
#> $tn
#> [1] 202
#> 
#> $fn
#> [1] 93
#> 
#> attr(,"class")
#> [1] "confusion_matrix"
#> 
#> attr(,"class")
#> [1] "group_matrices"