| detect_cp | R Documentation |
The detect_cp function detect change points on univariate and multivariate time series.
detect_cp(
data,
n_iterations,
n_burnin = 0,
q = 0.5,
params = list(),
kernel,
print_progress = TRUE,
user_seed = 1234
)
data |
a vector or a matrix. If a vector the algorithm for univariate time series is used. If a matrix, where rows are the observations and columns are the times, then the algorithm for multivariate time series is used. |
n_iterations |
number of MCMC iterations. |
n_burnin |
number of iterations that must be excluded when computing the posterior estimate. |
q |
probability of performing a split at each iteration. |
params |
a list of parameters: If data is an univariate time series the following must be specified:
If the time series is multivariate the following must be specified:
If data are survival functions:
|
kernel |
can be "ts" if data are time series or "epi" if data are survival functions. |
print_progress |
If TRUE (default) print the progress bar. |
user_seed |
seed for random distribution generation. |
A DetectCpObj class object containing
$data vector or matrix with the data.
$n_iterations number of iterations.
$n_burnin number of burn-in iterations.
$orders matrix where each entries is the assignment of the realization to a block. Rows are the iterations and columns the times.
$time computational time.
$gammaMCMC traceplot for \gamma.
$phi_MCMC_01 a 0/1 vector, the n-th element is equal to 1 if the proposed \gamma was accepted, 0 otherwise.
$sigma_MCMC traceplot for \sigma.
$sigma_MCMC_01 a 0/1 vector, the n-th element is equal to 1 if the proposed \sigma was accepted, 0 otherwise.
$theta_MCMC traceplot for \theta.
I0_MCMC traceplot for I_0.
I0_MCMC_01 a 0/1 vector, the n-th element is equal to 1 if the proposed I_0 was accepted, 0 otherwise.
kernel_ts if TRUE data are time series.
kernel_epi if TRUE data are survival functions.
$univariate_ts TRUE if data is an univariate time series, FALSE if it is a multivariate time series.
Martínez, A. F., & Mena, R. H. (2014). On a Nonparametric Change Point Detection Model in Markovian Regimes. Bayesian Analysis, 9(4), 823–858. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/14-BA878")}
Corradin, R., Danese, L., & Ongaro, A. (2022). Bayesian nonparametric change point detection for multivariate time series with missing observations. International Journal of Approximate Reasoning, 143, 26–43. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.ijar.2021.12.019")}
Corradin, R., Danese, L., KhudaBukhsh, W. R., & Ongaro, A. (2024). Model-based clustering of time-dependent observations with common structural changes. arXiv preprint arXiv:2410.09552.
## Univariate time series
data_vec <- as.numeric(c(rnorm(50,0,0.1), rnorm(50,1,0.25)))
out <- detect_cp(data = data_vec, n_iterations = 2500, n_burnin = 500,
params = list(a = 1, b = 1, c = 0.1), kernel = "ts")
print(out)
## Multivariate time series
data_mat <- matrix(NA, nrow = 3, ncol = 100)
data_mat[1,] <- as.numeric(c(rnorm(50,0,0.100), rnorm(50,1,0.250)))
data_mat[2,] <- as.numeric(c(rnorm(50,0,0.125), rnorm(50,1,0.225)))
data_mat[3,] <- as.numeric(c(rnorm(50,0,0.175), rnorm(50,1,0.280)))
out <- detect_cp(data = data_mat, n_iterations = 2500, n_burnin = 500,
params = list(m_0 = rep(0,3), k_0 = 0.25, nu_0 = 4,
S_0 = diag(1,3,3)), kernel = "ts")
print(out)
## Survival functions
data_mat <- matrix(NA, nrow = 1, ncol = 100)
betas <- c(rep(0.45, 25),rep(0.14,75))
inf_times <- sim_epi_data(10000, 10, 100, betas, 1/8)
inf_times_vec <- rep(0,100)
names(inf_times_vec) <- as.character(1:100)
for(j in 1:100){
if(as.character(j) %in% names(table(floor(inf_times)))){
inf_times_vec[j] = table(floor(inf_times))[which(names(table(floor(inf_times))) == j)]
}
}
data_mat[1,] <- inf_times_vec
out <- detect_cp(data = data_mat, n_iterations = 500, n_burnin = 100,
params = list(M = 250, xi = 1/8, a0 = 40, b0 = 10), kernel = "epi")
print(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.