Introduction to AIBias: Longitudinal Bias Auditing

Overview

Standard fairness audits treat bias as a snapshot — a single-point disparity measurement at one moment in time. But in sequential decision systems (loan approvals, parole reviews, hiring pipelines, credit scoring), decisions at time \(t\) feed back into the features available at time \(t+1\).

AIBias treats algorithmic bias as a longitudinal process. It tracks:


The Synthetic Lending Dataset

The package ships with lending_panel, a 600-applicant × 6-year panel of synthetic loan decisions across three racial groups.

data(lending_panel)
head(lending_panel)
#>   applicant_id year     race income credit_score approved
#> 1     APP_0001 2015 Hispanic     58          719        1
#> 2     APP_0001 2016 Hispanic     69          759        1
#> 3     APP_0001 2017 Hispanic     59          580        1
#> 4     APP_0001 2018 Hispanic     69          677        1
#> 5     APP_0001 2019 Hispanic     56          674        0
#> 6     APP_0001 2020 Hispanic     57          619        0
# Pooled approval rates by group
tapply(lending_panel$approved, lending_panel$race, mean) |> round(3)
#>    White    Black Hispanic 
#>    0.775    0.514    0.579

Even from this simple tabulation we see a gap. But it misses the dynamic story: are disadvantaged groups less able to recover from a denial? Are gaps widening over time?


Step 1 — Build the Audit Object

obj <- aib_build(
  data     = lending_panel,
  id       = "applicant_id",
  time     = "year",
  group    = "race",
  decision = "approved"
)
print(obj)
#> 
#> == AIBias Audit Object ==
#>   Units       : 600 
#>   Time points : 6 ( 2015, 2016, 2017, 2018, 2019, 2020 )
#>   Groups      : White, Black, Hispanic 
#>   Decision    : approved 
#> 
#>   Components populated:
#>     ✕ bias 
#>     ✕ transitions 
#>     ✕ amplification 
#>     ✕ decomposition 
#>     ✕ adjusted 
#>     ✕ bootstrap

Step 2 — Describe Bias Trajectories

aib_describe() computes:

obj <- aib_describe(obj, ref_group = "White")
obj$bias$cumulative
#> # A tibble: 2 × 7
#>   group    ref_group CB_raw CB_normalized CB_smd peak_disparity time_to_peak
#>   <chr>    <chr>      <dbl>         <dbl>  <dbl>          <dbl>        <int>
#> 1 Black    White      -1.56        -0.261  -3.31          0.292            3
#> 2 Hispanic White      -1.17        -0.196  -2.49          0.304            3

The cumulative burden (CB_normalized) summarizes the average disparity experienced across all waves — a single policy-facing number.

Trajectory Plot

plot(obj, type = "trajectory")

Bias trajectory plot

Both groups show a persistent negative disparity from wave 1. The gap is relatively stable. The decomposition in Step 5 shows what keeps it stable.

Heatmap — Disparity Surface

plot(obj, type = "heatmap")

Group-time disparity heatmap

The heatmap displays the full group × time disparity surface. Red cells indicate disadvantaged periods.


Step 3 — Transition Analysis

The key question for compounding bias: are disadvantaged groups less likely to recover after a denial, and less likely to retain approval?

obj <- aib_transition(obj, ref_group = "White")

# Recovery and retention gaps
obj$transitions$recovery_gap
#> # A tibble: 2 × 4
#>   group    p_recovery_g p_recovery_ref recovery_gap
#>   <fct>           <dbl>          <dbl>        <dbl>
#> 1 Black           0.41           0.656       -0.246
#> 2 Hispanic        0.464          0.656       -0.193
obj$transitions$retention_gap
#> # A tibble: 2 × 4
#>   group    p_retention_g p_retention_ref retention_gap
#>   <fct>            <dbl>           <dbl>         <dbl>
#> 1 Black            0.629           0.821        -0.192
#> 2 Hispanic         0.670           0.821        -0.151
plot(obj, type = "transition")

Transition probabilities plot

After a denial, Black and Hispanic applicants are approved the next year less often than White applicants (the recovery gap), and after an approval they keep it less often (the retention gap).

By default, transitions link each decision to the decision at the immediately preceding scheduled occasion (lag = "scheduled"). A unit that misses an occasion contributes no transition into the next one. Use lag = "recorded" to link each decision to the unit’s previous data row instead, which is what AIBias 0.1.1 did. The two agree on balanced panels.

Markov State Evolution

The Markov amplification operator \(A^{state}_{g,r}(T) = \sum_t \|v_g(t) - v_r(t)\|\) quantifies cumulative divergence in state distributions:

obj$transitions$amp_state
#> # A tibble: 2 × 2
#>   group    A_state
#>   <chr>      <dbl>
#> 1 Black       1.56
#> 2 Hispanic    1.15

Step 4 — Amplification Index

The amplification index contrasts the gap among units with a favorable prior decision and the gap among units with an unfavorable one:

\[A_{g,r}(t) = B_{g,r}(t \mid 1) - B_{g,r}(t \mid 0).\]

Under the default sign = "mechanism", aib_amplify() reports \(-A_{g,r}(t)\), which equals the recovery gap minus the retention gap. Negative values mean the focal group’s shortfall after a denial is larger than its shortfall after an approval.

obj <- aib_amplify(obj, ref_group = "White")
obj$amplification$cumulative
#> # A tibble: 2 × 5
#>   group    A_cumulative  A_mean A_max T_amplifying
#>   <chr>           <dbl>   <dbl> <dbl>        <int>
#> 1 Black          -0.266 -0.0533 0.288            5
#> 2 Hispanic       -0.212 -0.0423 0.187            5
plot(obj, type = "amplification")

Amplification index plot

The index says whether the conditional gap depends on the prior decision. It does not say whether the overall gap is growing. The next section shows a case where the index is exactly zero and the gap still widens.


Step 5 — Why Did the Gap Change?

A zero index with a widening gap

Suppose both groups start with 50% favorable decisions. The reference group recovers with probability 0.2 and retains with probability 0.8; the focal group recovers with 0.1 and retains with 0.7. Both conditional gaps equal \(-0.10\), so the amplification index is zero. Yet the approval gap goes from 0 to \(-0.10\) to \(-0.16\).

sim <- aib_simulate(n = 20000, n_times = 3, groups = c("ref", "focal"),
                    init = c(0.5, 0.5), p01 = c(0.2, 0.1),
                    p11 = c(0.8, 0.7), seed = 2026)
zobj <- aib_build(sim, "id", "time", "group", "decision", verbose = FALSE)
zobj <- aib_transition(zobj, ref_group = "ref", verbose = FALSE)
zobj <- aib_amplify(zobj, ref_group = "ref", verbose = FALSE)
round(zobj$amplification$index$A_index, 3)
#> [1]  0.000 -0.003
zobj <- aib_decompose(zobj, ref_group = "ref", verbose = FALSE)
zobj$decomposition$steps[, c("time_from", "time_to", "gap_prev", "gap_curr",
                             "carry", "recovery", "retention")]
#> # A tibble: 2 × 7
#>   time_from time_to gap_prev gap_curr    carry recovery retention
#>   <chr>     <chr>      <dbl>    <dbl>    <dbl>    <dbl>     <dbl>
#> 1 1         2        0.00815  -0.0956  0.00483  -0.0501   -0.0502
#> 2 2         3       -0.0956   -0.159  -0.0573   -0.0567   -0.0452

The gap widens because the focal group enters the second step with fewer approvals, and approvals persist (carry), on top of the recovery and retention gaps.

The decomposition

aib_decompose() makes this exact for any panel. For each pair of consecutive occasions it takes the units with a recorded decision at both (the paired units) and splits the current gap among them as

\[\Delta^P_t = \bar s\,\Delta^P_{t-1} + (1-\bar q)\,\Delta p_{01} + \bar q\,\Delta p_{11},\]

where \(\bar q\) is the two groups’ average share favorable at \(t-1\), \(\bar s\) their average retention-minus-recovery rate, and \(\Delta\) means focal minus reference. Two more terms, \(S_{t-1}\) and \(S_t\), record how far the full observed gap at each occasion differs from the paired gap. The change in the observed gap is then

\[\Delta_t - \Delta_{t-1} = \underbrace{(\bar s - 1)\Delta^P_{t-1}}_{\text{decay}} + \underbrace{(1-\bar q)\Delta p_{01}}_{\text{recovery}} + \underbrace{\bar q\,\Delta p_{11}}_{\text{retention}} + \underbrace{(S_t - S_{t-1})}_{\text{sample change}}.\]

The decay term is the part of the prior gap that does not carry forward. The identity is exact for the recorded data; it needs no assumption that prior decisions cause later ones.

obj <- aib_decompose(obj, ref_group = "White")
obj$decomposition$totals
#> # A tibble: 2 × 11
#>   group gap_first gap_last change decay recovery retention sample_change n_steps
#>   <chr>     <dbl>    <dbl>  <dbl> <dbl>    <dbl>     <dbl>         <dbl>   <int>
#> 1 Black    -0.252   -0.238 0.0140 1.07    -0.437    -0.620             0       5
#> 2 Hisp…    -0.153   -0.113 0.0402 0.871   -0.325    -0.506             0       5
#> # ℹ 2 more variables: n_unsupported <int>, n_sparse <int>
plot(obj, type = "decomposition")

Decomposition of the change in the gap

In the lending panel the gap for Black applicants barely moves, but not because it carries forward. Approval persists only weakly (\(\bar s\) is small), so each year most of the prior gap decays. The recovery and retention gaps recreate it at every decision. A remedy aimed only at past denials would leave most of this gap in place.

The panel is complete, so the sample terms are zero. When decisions are missing, aib_decompose() reports how many units were present, how many had a decision and how many were paired, and flags steps where a prior-state cell is empty (supported = FALSE) or smaller than min_cell (sparse = TRUE).


Step 6 — Covariate Adjustment

To separate “case mix” differences from residual disparity, fit a covariate-adjusted model:

obj <- aib_adjust(
  obj,
  formula   = ~ income + credit_score,
  method    = "glm",
  ref_group = "White"
)

# Adjusted trajectory
head(obj$adjusted$trajectory)

Step 7 — Bootstrap Intervals

aib_bootstrap() resamples whole applicant histories and recomputes every component already in the object, including the decomposition.

obj <- aib_bootstrap(obj, B = 500, seed = 2024, conf = 0.95)
subset(obj$bootstrap$intervals, component == "decomposition_total")
plot(obj, type = "decomposition")  # adds intervals for the observed change

One-Shot: aib_audit()

Run the full pipeline in one call:

result <- aib_audit(
  lending_panel,
  id        = "applicant_id",
  time      = "year",
  group     = "race",
  decision  = "approved",
  ref_group = "White",
  decompose = TRUE,
  bootstrap = TRUE,
  B         = 200,
  seed      = 42
)

summary(result)

A Note on Interpretation

If at every occasion \(p_g^{11}(t) \le p_r^{11}(t)\), \(p_g^{01}(t) \le p_r^{01}(t)\) and \(p_r^{11}(t) \ge p_r^{01}(t)\), and both groups start at the same rate, then the focal group’s favorable-decision rate never exceeds the reference group’s. The gap need not widen at every step, however, and it can level off. The decomposition shows which terms hold it where it is.

All quantities here describe recorded decisions. Reading the transition gaps or the decomposition as effects of earlier decisions on later ones requires assumptions about how decisions and observation are generated.


Summary of Core Estimands

Estimand Function Formula
Bias trajectory aib_describe() \(B_{g,r}(t)\)
Standardized trajectory aib_describe() \(B^*_{g,r}(t)\)
Cumulative burden aib_describe() \(CB_{g,r}(T)\)
Recovery gap aib_transition() \(\Delta^{01}_{g,r}\)
Retention gap aib_transition() \(\Delta^{11}_{g,r}\)
Amplification index aib_amplify() \(A_{g,r}(t)\)
Gap decomposition aib_decompose() decay, recovery, retention, sample change
Bias persistence aib_persistence() \(PB_{g,r}(c)\)