| Title: | Pi-Change: Change Point Detection with Prior-Informed Penalties |
|---|---|
| Description: | PI-Change is a prior-informed multiple change point detection method that incorporates prespecified plausible change point locations through a time-varying penalized likelihood. The method extends multiple change point detection beyond purely data-driven segmentation by allowing external knowledge about plausible change point locations to enter the objective function; see Jacobs and Chen (2026) <doi:10.48550/arXiv.2605.01003>. |
| Authors: | Jonathon Jacobs [aut, cph], Shanshan Chen [aut, cre, cph] |
| Maintainer: | Shanshan Chen <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.6 |
| Built: | 2026-09-27 10:08:40 UTC |
| Source: | https://github.com/shanshanchen-biostat/pichange |
PI-Change detects multiple change points while allowing prespecified
plausible locations to lower the local penalty. A typical analysis first
records the prior assumptions with construct_penalty() and then fits the
segmentation with pi_change(). The fitted object retains the observations,
time index, prior specification, penalty, model settings, and ordered change
points.
Maintainer: Shanshan Chen [email protected] [copyright holder]
Authors:
Jonathon Jacobs [email protected] [copyright holder]
Jacobs, J. and Chen, S. (2026). "Pi-Change: A Prior-Informed Multiple Change Point Detection Algorithm." doi:10.48550/arXiv.2605.01003.
Build prior weights using non-overlapping center windows
build_prior_location(n, centers, width, type = "gaussian")build_prior_location(n, centers, width, type = "gaussian")
n |
Integer time series length. |
centers |
Numeric vector of prior centers. |
width |
Positive numeric width parameter. |
type |
Prior shape. One of |
Numeric vector of prior-support weights.
Extract PI-Change change points
changepoints(object, ...) ## S3 method for class 'pi_change_fit' changepoints(object, scale = c("index", "time"), boundaries = FALSE, ...)changepoints(object, ...) ## S3 method for class 'pi_change_fit' changepoints(object, scale = c("index", "time"), boundaries = FALSE, ...)
object |
A fitted |
... |
Reserved for future methods. |
scale |
Return observation |
boundaries |
Include the beginning and ending boundaries. |
A vector of detected change point locations.
Constructs the time-varying penalty used by PI-Change and records the prior
assumptions used to create it. Observed response values are not needed;
supply either the number of observations (n) or their ordered time index
(time). Prior widths are measured in observation positions, including when
prior locations are supplied as dates.
construct_penalty( n = NULL, centers, width, method, family, time = NULL, windows = NULL, max_penalty = NULL, minimum_penalty = NULL, const_ratio = NULL )construct_penalty( n = NULL, centers, width, method, family, time = NULL, windows = NULL, max_penalty = NULL, minimum_penalty = NULL, const_ratio = NULL )
n |
Number of observations. Supply exactly one of |
centers |
Prespecified plausible change point locations. Use observation
indices when supplying |
width |
Positive numeric scalar or vector specifying the prior width in observation positions. A vector must have one value per center. |
method |
Penalty construction method: |
family |
Segment distribution family: |
time |
Optional strictly increasing numeric, Date, or POSIXt vector. |
windows |
Optional list with components |
max_penalty, minimum_penalty
|
Penalty bounds required when
|
const_ratio |
Positive ratio required when |
A pi_penalty object containing the numeric penalty and complete
prior specification.
Jacobs, J. and Chen, S. (2026). "Pi-Change: A Prior-Informed Multiple Change Point Detection Algorithm." doi:10.48550/arXiv.2605.01003.
penalty <- construct_penalty( n = 80, centers = 40, width = 5, method = "mbic", family = "normal" ) penaltypenalty <- construct_penalty( n = 80, centers = 40, width = 5, method = "mbic", family = "normal" ) penalty
Processed workplace mobility summaries for the United States, New York City, the United Kingdom, and London. Values are mean percent changes from the pre-COVID baseline by date and region.
google_mobility_workplacesgoogle_mobility_workplaces
A data frame with columns:
Observation date.
Region label.
Mean workplace mobility percent change from baseline.
Google LLC, "Google COVID-19 Community Mobility Reports", https://www.google.com/covid19/mobility/, accessed July 17, 2026.
pi_change() locates change points in a univariate series using a
time-varying penalty from construct_penalty() or a user-supplied numeric
penalty. Scientific choices remain explicit: raw numeric penalties require
both family and criterion; a pi_penalty object supplies its recorded
family and can infer the "mbic" criterion when constructed by the MBIC
method.
pi_change( data, penalty, family = NULL, criterion = NULL, min_seg_len = 2L, time = NULL )pi_change( data, penalty, family = NULL, criterion = NULL, min_seg_len = 2L, time = NULL )
data |
Finite numeric vector containing the ordered series. |
penalty |
A |
family |
Segment distribution family, |
criterion |
Segment cost criterion, |
min_seg_len |
Integer minimum segment length. |
time |
Optional ordered numeric, Date, or POSIXt index. When the penalty contains a time index, that index is used by default. |
A pi_change_fit object. Use changepoints() to extract detected
locations and summary() or plot() to inspect the fit.
Jacobs, J. and Chen, S. (2026). "Pi-Change: A Prior-Informed Multiple Change Point Detection Algorithm." doi:10.48550/arXiv.2605.01003.
set.seed(1) x <- c(rnorm(40, 0, 0.3), rnorm(40, 2, 0.3)) penalty <- construct_penalty( n = length(x), centers = 40, width = 5, method = "mbic", family = "normal" ) fit <- pi_change(x, penalty, min_seg_len = 10) changepoints(fit)set.seed(1) x <- c(rnorm(40, 0, 0.3), rnorm(40, 2, 0.3)) penalty <- construct_penalty( n = length(x), centers = 40, width = 5, method = "mbic", family = "normal" ) fit <- pi_change(x, penalty, min_seg_len = 10) changepoints(fit)
Evaluate concatenated Gaussian prior weights
pi_concat(t, centers, sigma, window = NULL)pi_concat(t, centers, sigma, window = NULL)
t |
Numeric vector of locations at which to evaluate the prior. |
centers |
Numeric vector of prior centers. |
sigma |
Positive numeric scalar or vector of prior widths. |
window |
Optional list with components |
Numeric vector of prior-support weights in [0, 1].
Displays the time-varying penalty above the observed series when the fit
contains a pi_penalty specification. Prior centers and detected change
points use both distinct colors and line types. Horizontal fitted lines show
the estimated mean within each segment.
## S3 method for class 'pi_change_fit' plot( x, ..., xlab = NULL, ylab = "Observed value", show_prior = TRUE, show_fitted = TRUE, show_penalty = TRUE, data_col = "#76BDE8", fitted_col = "#F06292", changepoint_col = "#00C853", prior_col = "#D62728", penalty_col = "#D62728", series_linewidth = 0.5, fitted_linewidth = 0.5, vertical_linewidth = 1, title = "PI-Change detection" )## S3 method for class 'pi_change_fit' plot( x, ..., xlab = NULL, ylab = "Observed value", show_prior = TRUE, show_fitted = TRUE, show_penalty = TRUE, data_col = "#76BDE8", fitted_col = "#F06292", changepoint_col = "#00C853", prior_col = "#D62728", penalty_col = "#D62728", series_linewidth = 0.5, fitted_linewidth = 0.5, vertical_linewidth = 1, title = "PI-Change detection" )
x |
A fitted |
... |
Reserved for future extensions. |
xlab, ylab
|
Axis labels for the data-series panel. |
show_prior |
Show prespecified prior centers. |
show_fitted |
Show fitted segment means. |
show_penalty |
Show the penalty panel when a structured penalty is available. |
data_col, fitted_col, changepoint_col, prior_col, penalty_col
|
Colors for the observations, segment means, detected changes, prior centers, and penalty curve. |
series_linewidth, fitted_linewidth, vertical_linewidth
|
Line widths for the observed series, segment means, and vertical prior/change lines. |
title |
Optional title for the data-series panel. |
Invisibly, a named list containing the penalty and data ggplots
when the penalty panel is displayed; otherwise, the data-series ggplot.
Simulate zero-adjusted gamma observations
rzag(n, shape, scale, p0)rzag(n, shape, scale, p0)
n |
Number of observations. |
shape |
Gamma shape parameter. |
scale |
Gamma scale parameter. |
p0 |
Probability of observing zero. |
Numeric vector of simulated observations.
rzag(5, shape = 1, scale = 2, p0 = 0.25)rzag(5, shape = 1, scale = 2, p0 = 0.25)
Summarize a PI-Change fit
## S3 method for class 'pi_change_fit' summary(object, ...)## S3 method for class 'pi_change_fit' summary(object, ...)
object |
A fitted |
... |
Reserved for future methods. |
A summary.pi_change_fit object with segment summaries.
West Texas Intermediate spot prices at Cushing, Oklahoma from 2000 through 2009, with the absolute daily price change used in the oil-price vignette.
wti_oilwti_oil
A data frame with columns:
Observation date.
WTI spot price in dollars per barrel.
Absolute first difference in price.
U.S. Energy Information Administration, Cushing, Oklahoma WTI Spot Price FOB, available from https://www.eia.gov/dnav/pet/hist/rwtcd.htm.