Skip to contents

Implements basic Adaptive Conformal Inference (ACI) for sequential prediction. The miscoverage level alpha is adjusted online based on whether previous predictions covered the true values, maintaining long-run coverage even under distribution shift.

Usage

conformal_aci(y_pred, y_true, alpha = 0.1, gamma = 0.005)

Arguments

y_pred

A numeric vector of point predictions (sequential).

y_true

A numeric vector of true values (sequential).

alpha

Target miscoverage level. Default 0.10.

gamma

Learning rate for alpha adjustment. Default 0.005. Larger values adapt faster but are less stable.

Value

A list with components:

lower

Numeric vector of lower bounds.

upper

Numeric vector of upper bounds.

covered

Logical vector indicating whether each interval covered the true value.

alphas

Numeric vector of the adapted alpha values at each step.

coverage

Overall empirical coverage.

Details

ACI provides asymptotic coverage guarantees under distribution drift, not the finite-sample guarantees of split conformal prediction. The long-run average coverage converges to \(1 - \alpha\) as the sequence length grows (Gibbs and Candes, 2021).

References

Gibbs, I. and Candes, E. (2021). Adaptive conformal inference under distribution shift. Advances in Neural Information Processing Systems, 34.

Examples

set.seed(42)
n <- 200
y_true <- cumsum(rnorm(n, sd = 0.1)) + rnorm(n)
y_pred <- c(0, y_true[-n])  # naive lag-1 prediction

result <- conformal_aci(y_pred, y_true, alpha = 0.10, gamma = 0.01)
print(result$coverage)
#> [1] 0.99