aib_build: Build an AIBias audit object

View source: R/aib_build.R

aib_buildR Documentation

Build an AIBias audit object

Description

Constructs the core 'aibias' S3 object from a panel dataset. Validates the panel structure and prepares internal data for downstream analysis.

Usage

aib_build(
  data,
  id,
  time,
  group,
  decision,
  outcome = NULL,
  verbose = TRUE,
  schedule = NULL
)

Arguments

data

A data frame in long (panel) format.

id

Character. Name of the unit identifier column.

time

Character. Name of the time/wave column (integer or factor).

group

Character. Name of the protected group column.

decision

Character. Name of the binary decision column. Numeric 0/1, logical, or character/factor with values "0"/"1" or "TRUE"/"FALSE" (any case); 'NA' marks a present unit without a recorded decision. Any other value is an error.

outcome

Character or NULL. Optional downstream outcome column.

verbose

Logical. Print validation messages. Default TRUE.

schedule

Optional vector of all scheduled occasions, in order. Use it when an occasion may be absent from 'data' altogether, so that the occasions on either side are not treated as consecutive. If NULL, the levels of 'time' are used when it is a factor (including unused levels), otherwise its sorted unique values. Every value of 'time' must appear in the schedule.

Details

The function expects a balanced or unbalanced panel where: - 'id' indexes units observed over multiple periods - 'time' is an ordered index, mapped to its position in the schedule - 'group' is a categorical variable indicating protected group membership - 'decision' is a binary 0/1 variable (1 = favorable decision)

Each unit may have at most one row per occasion. A row whose decision is 'NA' marks a unit that was present (for example, eligible or enrolled) at that occasion but has no recorded decision. [AIBias::aib_decompose()] reports such units separately from units with no row at all.

Group membership is taken from ‘group' at each row. If a unit’s group changes over time, 'aib_build()' warns; trajectory and transition summaries can still be computed, but [AIBias::aib_decompose()] and [AIBias::aib_bootstrap()] stop, because both follow units over time and need one group per unit.

Value

An object of class '"aibias"'.

Examples

data(lending_panel)
obj <- aib_build(lending_panel,
                 id       = "applicant_id",
                 time     = "year",
                 group    = "race",
                 decision = "approved")


AIBias documentation built on Dec. 1, 2026, 1:06 a.m.