tmpaud
Disparity metrics over time and place
tmpaud(pred, grp = NULL, period = NULL, city = NULL, base = NULL)The disparate impact ratio, the parity gap, the Gini coefficient of the
groups’ shares flagged and the bias amplification score of fairdf(),
for every city and period, and how far each city’s ratio moves over the
periods (after Barman and Barman 2026).
Parameters
Section titled “Parameters”predThe tool’s decisions: 1 (or
TRUE) for a case it flags, 0 (orFALSE) otherwise, one per case. Aclprelist fromclprep()is taken too: its elements fill the arguments by name.grpGroup labels: numbers, text or a factor, one per case, no missing values. Groups are ordered as the factor’s levels, or sorted.
periodThe period of each case: labels (text, numbers or a factor), sorted as
fair()sorts groups; ISO dates as text sort in time order.cityNULL(one place, labelled"all"), or the city of each case: labels.baseThe base group:
NULLfor the group with the largest share flagged (the first in order on ties), its label, or its position from 1.
Returns
Section titled “Returns”A list: cells, a data frame with one row per city and period
that occurs: city, period, n, ok (TRUE when audited), di,
dp, gini and bas (NaN when skipped); cities, one row per
city: city, ncell (cells audited), di, dp, gini, bas (their
means), dimin, dimax, dirng and ngt1; sum, rng (the largest
range) and spread (largest minus smallest mean ratio of the cities;
NaN with fewer than two); base.
A cell (one city in one period) is audited when it holds at least two groups and the base group; otherwise it is reported and skipped. The base group is the same in every cell: by default the group with the largest share flagged over all the data. For each city, the means of the four values over its audited cells (finite values only), the smallest and largest ratio, their range, and how many periods have a ratio above
- A ratio that moves a lot from one period to the next says that one audit at one time describes that time only; a spread between cities says the same tool can treat groups differently in different places. Neither says why. For intervals on one cell, call
fairdf()on it.
Examples
Section titled “Examples”set.seed(2)n <- 600g <- sample(c("a", "b"), n, TRUE)per <- sample(c("2024-1", "2024-2", "2024-3"), n, TRUE)cty <- sample(c("north", "south"), n, TRUE)p <- rbinom(n, 1, ifelse(g == "a", 0.4, ifelse(cty == "north", 0.3, 0.2)))tmpaud(p, g, per, cty)$citiesAlso in the R reference, with the method and its source.