aib_simulate: Simulate repeated binary decisions with selective observation

View source: R/aib_simulate.R

aib_simulateR Documentation

Simulate repeated binary decisions with selective observation

Description

Generates a panel of repeated 0/1 decisions that follow a two-state Markov chain within each group, and optionally hides decisions with a probability that depends on the group and on the unit's previous (true) decision. Useful for checking an audit against known components and for teaching.

Usage

aib_simulate(
  n = 500,
  n_times = 4,
  groups = c("reference", "focal"),
  init = c(0.5, 0.5),
  p01 = c(0.2, 0.1),
  p11 = c(0.8, 0.7),
  observe = NULL,
  unobserved = c("na", "drop"),
  seed = NULL
)

Arguments

n

Integer. Units per group (scalar, or one value per group).

n_times

Integer. Number of occasions (at least 2).

groups

Character. Group labels; the first is used as the reference group in the examples.

init

Numeric. Probability of a favorable first decision, one per group.

p01

Numeric. Recovery probability Pr(D_t = 1 | D_{t-1} = 0), one per group.

p11

Numeric. Retention probability Pr(D_t = 1 | D_{t-1} = 1), one per group.

observe

NULL for complete observation, or a 2-row matrix of observation probabilities with one column per group: row 1 after an unfavorable previous decision, row 2 after a favorable one. The first occasion is always observed.

unobserved

Character. '"na"' (default) keeps unobserved occasions as rows with a missing decision; '"drop"' removes them.

seed

Integer or NULL. Random seed.

Value

A data frame with columns 'id', 'time', 'group', 'decision' and 'decision_true' (the decision before any hiding).

Examples

# Equal recovery and retention gaps (zero amplification index),
# yet the approval gap widens.
sim <- aib_simulate(n = 2000, n_times = 4, groups = c("ref", "focal"),
                    init = c(0.5, 0.5), p01 = c(0.2, 0.1),
                    p11 = c(0.8, 0.7), seed = 1)
obj <- aib_build(sim, "id", "time", "group", "decision", verbose = FALSE)
obj <- aib_decompose(obj, ref_group = "ref")


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