Skip to contents

Wraps changepoints::CV.search.DP.regression() (Rinaldo, Wang, Wen, Willett and Yu): dynamic programming with an \(\ell_0\) penalty for changes in the coefficient vector of a high-dimensional sparse regression, with the two tuning parameters chosen by cross-validation. Where strucchange_wrapper() dates breaks in a low-dimensional regression by dynamic programming on the residual sum of squares, this handles the case where there are more covariates than the segments have observations to fit them with.

Usage

hdreg_wrapper(
  x,
  response = NULL,
  gamma_set = NULL,
  lambda_set = NULL,
  delta = NULL,
  ...
)

Arguments

x

A numeric matrix or data frame of covariates, rows as time points.

response

A numeric vector of responses, one per row of x. Required. Reachable through cpt_detect() as cpt_detect(X, method = "hdreg", response = y).

gamma_set

Candidate values of the \(\ell_0\) tuning parameter. Defaults to a small grid scaled by the series length.

lambda_set

Candidate lasso penalties. Defaults to c(0.01, 0.1, 1).

delta

Minimum spacing. Defaults to max(5, floor(n / 20)).

...

Additional arguments passed to the engine.

Value

A ggcpt object with change_in = "regression". The plotted series is the response, which is what a reader of a regression-break plot expects to see.

References

Rinaldo A, Wang D, Wen Q, Willett R, Yu Y (2021). “Localizing changes in high-dimensional regression models.” In Proceedings of the 24th International Conference on Artificial Intelligence and Statistics, volume 130 of Proceedings of Machine Learning Research, 2089–2097.

Examples

# \donttest{
set.seed(2026)
p <- 10
n <- 80
X <- matrix(stats::rnorm(n * p), n, p)
beta1 <- c(rep(2, 3), rep(0, p - 3))
beta2 <- c(rep(0, p - 3), rep(2, 3))
y <- c(X[1:40, ] %*% beta1, X[41:n, ] %*% beta2) + stats::rnorm(n)
hdreg_wrapper(X, response = y, gamma_set = c(1, 10),
              lambda_set = c(0.1, 1))
#> ggcpt (changepoint detection result)
#>   Method:         hdreg
#>   Change in:       regression 
#>   Changepoints found: 1 
#>   CP convention:   left 
#>   Penalty:         l0 (CV) 
#>   Series length:   80 
#> 
#> Changepoints:
#> # A tibble: 1 × 2
#>      cp cp_value
#>   <int>    <dbl>
#> 1    39     2.90
# }