CV.search.DP.regression {changepoints}R Documentation

Grid search based on cross-validation of dynamic programming for regression change points localisation with l_0 penalisation.

Description

Perform grid search to select tuning parameters gamma (for l_0 penalty of DP) and lambda (for lasso penalty) based on cross-validation.

Usage

CV.search.DP.regression(y, X, gamma_set, lambda_set, delta, eps = 0.001)

Arguments

y

A numeric vector of response variable.

X

A numeric matrix of covariates with vertical axis being time.

gamma_set

A numeric vector of candidate tuning parameters associated with l_0 penalty of DP.

lambda_set

A numeric vector of candidate tuning parameters for lasso penalty.

delta

A strictly positive integer scalar of minimum spacing.

eps

A numeric scalar of precision level for convergence of lasso.

Value

A list with the following structure:

cpt_hat

A list of vector of estimated change points

K_hat

A list of scalar of number of estimated change points

test_error

A list of vector of testing errors (each row corresponding to each gamma, and each column corresponding to each lambda)

train_error

A list of vector of training errors

Author(s)

Daren Wang

References

Rinaldo, Wang, Wen, Willett and Yu (2020) <arxiv:2010.10410>

Examples

d0 = 10
p = 20
n = 100
cpt_true = c(30, 70)
data = simu.change.regression(d0, cpt_true, p, n, sigma = 1, kappa = 9)
gamma_set = c(0.01, 0.1, 1)
lambda_set = c(0.01, 0.1, 1, 3)
temp = CV.search.DP.regression(y = data$y, X = data$X, gamma_set, lambda_set, delta = 2)
temp$test_error # test error result
# find the indices of gamma_set and lambda_set which minimizes the test error
min_idx = as.vector(arrayInd(which.min(temp$test_error), dim(temp$test_error))) 
gamma_set[min_idx[1]]
lambda_set[min_idx[2]]
cpt_init = unlist(temp$cpt_hat[min_idx[1], min_idx[2]])

[Package changepoints version 1.1.0 Index]