CV.search.DP.regression {changepoints} | R Documentation |
Grid search based on cross-validation of dynamic programming for regression change points localisation with
penalisation.
Description
Perform grid search to select tuning parameters gamma (for 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 |
X |
A |
gamma_set |
A |
lambda_set |
A |
delta |
A strictly positive |
eps |
A |
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]])