View source: R/civic_fairness.R
| civic_fairness | R Documentation |
Evaluates a 'civic_model' across levels of a protected attribute, computing standard algorithmic fairness metrics. Works for binary classification, multi-class classification, and regression.
**Binary classification metrics (per group):** 'n', 'acc', 'tpr', 'tnr', 'fpr', 'fnr', 'ppv', 'rate_pos', 'mean_prob', 'acc_gap', 'tpr_gap', 'fpr_gap', 'dp_ratio' (disparate impact), 'eo_gap' (equalized odds gap).
**Multi-class metrics (per group):** 'n', 'acc', 'balanced_acc', 'acc_gap'.
**Regression metrics (per group):** 'n', 'mae', 'rmse', 'mae_gap', 'rmse_gap'.
civic_fairness(
object,
data,
outcome,
protected,
positive = NULL,
threshold = 0.5
)
object |
A 'civic_model' from [civic_fit()]. |
data |
A 'data.frame' containing features, outcome, and protected column. |
outcome |
Character. Name of the outcome/target column. |
protected |
Character. Name of the protected attribute column (e.g., '"gender"', '"ethnicity"', '"age_group"'). |
positive |
Character. Positive class for binary classification. Defaults to 'object$positive'. |
threshold |
Decision threshold for binary classification (default '0.5'). |
A tibble of class 'civic_fairness' with one row per group.
# Binary classification
m <- civic_fit(voted ~ age + education, civic_voting)
civic_fairness(m, civic_voting, outcome = "voted",
protected = "gender", positive = "yes")
# Regression
m2 <- civic_fit(mpg ~ cyl + wt + hp, mtcars)
mtcars$gear_grp <- factor(mtcars$gear)
civic_fairness(m2, mtcars, outcome = "mpg", protected = "gear_grp")
# Any data — works with iris too
m3 <- civic_fit(Sepal.Length ~ Sepal.Width + Petal.Length, iris)
civic_fairness(m3, iris, outcome = "Sepal.Length", protected = "Species")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.