Skip to contents

Scores an online result the way the sequential literature does: how long after each true change did the first alarm arrive, and how many alarms were raised with no change behind them. cpt_metrics() is the wrong tool for an online detector: it asks whether the location was recovered, which a sequential procedure never claims. It will not stop you: cpt_metrics() takes bare integer vectors and never sees which detector produced them, so it cannot know. (An earlier version of this sentence said it warns. It does not, and given that signature it could not.)

Usage

cpt_delay(object, truth, max_delay = Inf)

# S3 method for class 'ggcpt_delay'
tidy(x, ...)

# S3 method for class 'ggcpt_delay'
glance(x, ...)

# S3 method for class 'ggcpt_delay'
print(x, ...)

# S3 method for class 'ggcpt_delay'
autoplot(object, ...)

Arguments

object

A ggcpt_delay object (for autoplot()).

truth

Integer vector of true changepoint positions, on the same clock as the alarms. When object is a monitor built by cpt_replay() the baseline offset is applied automatically.

max_delay

Alarms further than this after a change are treated as false alarms rather than late detections. Defaults to Inf.

x

A ggcpt_delay object.

...

Ignored.

Value

A ggcpt_delay object: a list with per_change (one row per true change: truth, alarm, delay, detected), false_alarms, and the summary statistics mean_delay, median_delay, n_false_alarms and arl: monitored observations per false alarm. The baseline a cpt_replay() monitor trained on is not counted, because no alarm can fire there; n_obs is the length of the stream in series positions, baseline included.

Examples

set.seed(2026)
mon <- cpt_replay(c(rnorm(200), rnorm(200, 3)), method = "edetector")
cpt_delay(mon, truth = 200)
#> ggcpt_delay
#>   True changes:       1
#>   Detected:           1
#>   Mean delay:         16
#>   Median delay:       16
#>   False alarms:       4
#>   Average run length: 75
#> 
#> # A tibble: 1 × 4
#>   truth alarm delay detected
#>   <int> <int> <dbl> <lgl>   
#> 1   200   216    16 TRUE