aib_decompose: Decompose the change in a group gap between consecutive...

View source: R/aib_decompose.R

aib_decomposeR Documentation

Decompose the change in a group gap between consecutive occasions

Description

For each pair of consecutive scheduled occasions (t-1, t) and each focal group g, splits the observed decision-rate gap \Delta_t = \pi_g(t) - \pi_r(t) into the prior gap carried forward, a recovery contribution, a retention contribution and two terms that link the units with decisions at both occasions to everyone with a decision at each occasion. The split is an accounting identity: the components add up to the observed change exactly.

Usage

aib_decompose(object, ref_group = NULL, min_cell = 10, verbose = TRUE)

Arguments

object

An 'aibias' object from [AIBias::aib_build()].

ref_group

Character. Reference group. If NULL, uses the first level.

min_cell

Integer. A step is flagged as sparse when any of the four prior-state cells (focal/reference by prior decision 0/1) among paired units has fewer than 'min_cell' units. Default 10.

verbose

Logical. Print a short summary.

Details

Let the *paired* units at step t be those with a recorded decision at both t-1 and t. Within group h among paired units, let q_h be the share with a favorable decision at t-1, and let p_{01,h} (recovery) and p_{11,h} (retention) be the shares favorable at t given an unfavorable or favorable decision at t-1. Write \Delta for focal minus reference, a bar for the average of the two groups, and s_h = p_{11,h} - p_{01,h}. The current gap among paired units is exactly

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

where \Delta^P_{t-1} = \Delta q is the prior gap among the same units (Kitagawa, 1955, symmetric weights). Writing S_t = \Delta_t - \Delta^P_t and S_{t-1} = \Delta_{t-1} - \Delta^P_{t-1} for the differences between the full observed gap and the paired gap at each occasion gives

\Delta_t - \Delta_{t-1} = (\bar s - 1)\Delta^P_{t-1} + (1-\bar q)\Delta p_{01} + \bar q\,\Delta p_{11} + (S_t - S_{t-1}).

The identity holds for any recorded data. It does not assume that the previous decision causes the current one, that the process is Markov, or that missing decisions are missing at random. Those assumptions matter only when the components are read as features of a population process.

Pairs always use consecutive scheduled occasions (integer time index). A unit that misses occasion t-1 contributes to the full gap at t but not to the paired quantities. A data row with a missing decision counts as present but unscored.

Each unit must belong to one group throughout; the function stops otherwise.

**Empty cells.** When a prior-state cell is empty, the step is marked 'supported = FALSE' and only the components that do not need the missing rate are returned: - always estimable (given both groups have recorded decisions): 'gap_prev', 'gap_curr', 'change', 'gap_pair_prev', 'gap_pair_curr', 'sample_prev', 'sample_curr', 'sample_change'; - 'recovery' needs paired units with an unfavorable prior decision in both groups ('n0_g', 'n0_ref' > 0); - 'retention' needs paired units with a favorable prior decision in both groups ('n1_g', 'n1_ref' > 0); - 'carry' and 'decay' need all four cells.

Components that cannot be estimated are 'NA', and so is 'recon_error', because the remaining components no longer add up to the change.

Value

The 'aibias' object with '$decomposition' populated, a list with - 'steps': one row per focal group and step, with counts, rates, gaps and components (see below) - 'totals': components summed over all steps, per focal group - 'ref_group', 'min_cell'

Key columns of 'steps': 'gap_prev', 'gap_curr' (full observed gaps), 'change' (their difference), 'gap_pair_prev', 'gap_pair_curr', 'carry' (\bar s\,\Delta^P_{t-1}), 'decay' ((\bar s-1)\Delta^P_{t-1}), 'recovery', 'retention', 'sample_prev' (S_{t-1}), 'sample_curr' (S_t), 'sample_change' (S_t - S_{t-1}), 'recon_error' (numerical check, zero up to rounding), the counts 'n_units_*' (units in the panel), 'n_present_*' (units with a data row), 'n_obs_*' (units with a recorded decision), 'n_pair_*' (paired units), 'n0_*' and 'n1_*' (paired units with an unfavorable or favorable prior decision), and the flags 'supported' and 'sparse'. Suffix '_g' is the focal group and '_ref' the reference group.

References

Kitagawa, E. M. (1955). Components of a difference between two rates. *Journal of the American Statistical Association*, 50(272), 1168–1194.

Examples

data(lending_panel)
obj <- aib_build(lending_panel, "applicant_id", "year", "race", "approved",
                 verbose = FALSE)
obj <- aib_decompose(obj, ref_group = "White")
obj$decomposition$steps[, c("group", "time_from", "time_to", "change",
                            "decay", "recovery", "retention",
                            "sample_change")]


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