| Title: | Change Point Detection for Non-Stationary and Cross-Correlated Time Series |
|---|---|
| Description: | Implements methods for multiple change point detection in multivariate time series with non-stationary dynamics and cross-correlations. The methodology is based on a model in which each component has a fluctuating mean represented by a random walk with occasional abrupt shifts, combined with a stationary vector autoregressive structure to capture temporal and cross-sectional dependence. The framework is broadly applicable to correlated multivariate sequences in which large, sudden shifts occur in all or subsets of components and are the primary targets of interest, whereas small, smooth fluctuations are not. Although random walks are used as a modeling device, they provide a flexible approximation for a wide class of slowly varying or locally smooth dynamics, enabling robust performance beyond the strict random walk setting. |
| Authors: | Yuhan Tian [aut, cre], Abolfazl Safikhani [aut] |
| Maintainer: | Yuhan Tian <[email protected]> |
| License: | GPL-2 |
| Version: | 0.1.2 |
| Built: | 2026-05-10 07:15:02 UTC |
| Source: | https://github.com/cran/FluxPoint |
Adds constant mean shifts to a multivariate time series by applying a fixed jump vector at evenly spaced change points. After each change point, all subsequent observations are shifted by the specified vector.
add_jumps(data, delta, num)add_jumps(data, delta, num)
data |
Numeric matrix of dimension |
delta |
Numeric vector of length |
num |
Integer; number of change points. The data are divided evenly
into |
The total length of the time series is denoted by . Change points are
placed at evenly spaced locations given by
, for . After each
change point, a constant shift vector delta is added to all subsequent
observations. This construction produces synthetic data with known and
controlled mean shifts, making the function useful for simulation studies and
benchmarking change point detection methods.
A numeric matrix of the same dimension as 'data', containing the adjusted series with added mean shifts.
Estimates the fluctuating mean sequence
segmentwise by applying the maximum likelihood estimation (MLE) procedure
within each segment defined by detected change points.
estimate_musseg(data, cps, Sig_eta, Sig_nu, Phi, Sig_e1)estimate_musseg(data, cps, Sig_eta, Sig_nu, Phi, Sig_e1)
data |
Numeric matrix of dimension |
cps |
Numeric vector of detected change point locations (sorted indices). |
Sig_eta |
Numeric |
Sig_nu |
Numeric |
Phi |
Numeric |
Sig_e1 |
Numeric |
The time series is partitioned into contiguous segments defined by the
specified change points. Within each segment,
estimate_mus is applied to obtain the maximum likelihood
estimate of the fluctuating mean sequence for that interval. The resulting
segment-wise estimates are then concatenated to form a complete piecewise
estimate of over the entire time series.
A numeric matrix of dimension , containing the estimated
fluctuating mean sequence across all segments.
set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(-2, 4, 0)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Generate data and estimate mean segmentwise after known CPs Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) cps <- c(100, 200) mu_seg <- estimate_musseg(Y, cps, Sig_eta, Sig_nu, Phi, Sig_e1) dim(mu_seg)set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(-2, 4, 0)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Generate data and estimate mean segmentwise after known CPs Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) cps <- c(100, 200) mu_seg <- estimate_musseg(Y, cps, Sig_eta, Sig_nu, Phi, Sig_e1) dim(mu_seg)
Applies the robust parameter estimation (RPE) procedure componentwise
to a multivariate time series in order to estimate the diagonal elements
of , , and
.
estimate_RWVAR_cp_heter( data, L = 15, phiLower = -0.8, phiUpper = 0.8, sigetaLower = 0, sigetaUpper = Inf, signuLower = 1e-06, signuUpper = Inf, num_inis = 20, CPs = NULL )estimate_RWVAR_cp_heter( data, L = 15, phiLower = -0.8, phiUpper = 0.8, sigetaLower = 0, sigetaUpper = Inf, signuLower = 1e-06, signuUpper = Inf, num_inis = 20, CPs = NULL )
data |
Numeric matrix of dimension |
L |
Integer; number of lag differences used in each univariate RPE estimation (default = 15). |
phiLower, phiUpper
|
Numeric; lower and upper bounds for the
autoregressive coefficient |
sigetaLower, sigetaUpper
|
Numeric; lower and upper bounds for
|
signuLower, signuUpper
|
Numeric; lower and upper bounds for
|
num_inis |
Integer; number of initial values of |
CPs |
Optional numeric vector of change point locations (indices). If provided, differenced data overlapping these points are removed for more robust estimation. |
This function performs the RPE procedure for each variable (column)
in 'data' independently, using estimate_RWVAR_cp as the
univariate estimator. The resulting estimates are combined into
diagonal matrices:
— estimated innovation covariance
of the VAR(1) component.
— estimated innovation covariance
of the random walk component.
— estimated autoregressive coefficient matrix.
A list containing:
'Sig_nu' — Diagonal matrix of estimated .
'Sig_eta' — Diagonal matrix of estimated .
'Phi' — Diagonal matrix of estimated autoregressive coefficients
.
set.seed(123) p <- 3 # True (diagonal) parameters for simulation mu0 <- rep(0, p) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) # diagonal here since num_nonzero = 0 Phi <- random_Phi(p, 0) # diagonal here since num_nonzero = 0 Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Two evenly spaced change points deltas <- list(c(3, 0, -3), c(-2, 4, 0)) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) # Provide CP locations to remove affected differences in RPE CPs <- c(100, 200) # Componentwise robust parameter estimation fit <- estimate_RWVAR_cp_heter(Y, L = 15, CPs = CPs) # Estimated diagonal matrices: fit$Sig_eta fit$Sig_nu fit$Phiset.seed(123) p <- 3 # True (diagonal) parameters for simulation mu0 <- rep(0, p) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) # diagonal here since num_nonzero = 0 Phi <- random_Phi(p, 0) # diagonal here since num_nonzero = 0 Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Two evenly spaced change points deltas <- list(c(3, 0, -3), c(-2, 4, 0)) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) # Provide CP locations to remove affected differences in RPE CPs <- c(100, 200) # Componentwise robust parameter estimation fit <- estimate_RWVAR_cp_heter(Y, L = 15, CPs = CPs) # Estimated diagonal matrices: fit$Sig_eta fit$Sig_nu fit$Phi
Estimates the non-diagonal autoregressive coefficient matrix
and innovation covariance matrix
for the residual process obtained after removing the estimated
fluctuating mean from the data. The estimation applies the
Lasso to encourage sparsity in the cross-variable dependence structure.
estimatePhinu_nondiag( epsilons, Sig_nu_diag, Phi_diag, replace_diag = FALSE, needReproduce = FALSE )estimatePhinu_nondiag( epsilons, Sig_nu_diag, Phi_diag, replace_diag = FALSE, needReproduce = FALSE )
epsilons |
Numeric matrix of dimension |
Sig_nu_diag |
Numeric |
Phi_diag |
Numeric |
replace_diag |
Logical; if |
needReproduce |
Logical; if |
The function applies a Lasso-penalized VAR(1) fit to the residual
process to estimate cross-dependencies
among variables.
The fitting is performed using the function
fitVAR(), which is adapted from the sparsevar package.
When replace_diag = TRUE, the diagonal entries of
and are replaced by
their componentwise estimates obtained in Phase I for improved
numerical stability.
A list containing:
'Phi_hat' — Estimated non-diagonal autoregressive matrix
.
'Sig_nu_hat' — Estimated non-diagonal innovation covariance
matrix .
Implements the full FluxPoint algorithm for detecting multiple change points in multivariate time series with non-stationary dynamics and cross-correlations. The procedure iteratively estimates model parameters and change point locations, alternating between parameter estimation and detection steps until convergence.
FluxPoint( data, w, tc, max_iter1, max_iter2, ignoreCross = FALSE, noeta = FALSE, nophi = FALSE, needReproduce = FALSE )FluxPoint( data, w, tc, max_iter1, max_iter2, ignoreCross = FALSE, noeta = FALSE, nophi = FALSE, needReproduce = FALSE )
data |
Numeric matrix of dimension |
w |
Integer specifying the window size used by the detector. |
tc |
Numeric tuning constant used in the detection threshold
|
max_iter1 |
Integer specifying the maximum number of iterations for the first-stage loop, which alternates between diagonal robust parameter estimation and change point detection. |
max_iter2 |
Integer specifying the maximum number of iterations for the second-stage refinement loop, which incorporates non-diagonal vector autoregressive updates. |
ignoreCross |
Logical; if |
noeta |
Logical; if |
nophi |
Logical; if |
needReproduce |
Logical; if |
The algorithm proceeds through the following stages:
Stage I (diagonal estimation): Robust parameter
estimation is performed to obtain diagonal estimates of
, , and
. These estimates are used to construct the windowed covariance
matrix and its inverse. Change point
detection is then carried out using the resulting detector statistic.
The estimation and detection steps are iterated until the detected change
points stabilize or max_iter1 is reached.
Stage II (refinement with cross-correlation): If enabled,
the fluctuating mean is estimated segmentwise and removed from the data.
A sparse vector autoregressive model is then fitted to the residuals to
obtain non-diagonal estimates of and
. The covariance matrix
is recomputed and change point detection
is rerun. This refinement loop is repeated until convergence or until
max_iter2 is reached.
A list containing:
cps: Sorted indices of the detected change points.
Sig_eta_hat: Final estimate of .
Sig_nu_hat: Final estimate of ,
which may be non-diagonal if the second-stage refinement is performed.
Phi_hat: Final estimate of , which may be
non-diagonal if the second-stage refinement is performed.
muhats: Estimated fluctuating mean sequence.
detectorStats: Detector statistic evaluated over time.
cps_at: A list mapping each detected change point to the
indices of components selected as contributing to that change.
Tian, Y. and Safikhani, A. (2025). Multiple change point detection in time series with non-stationary dynamics. Manuscript under review.
## Minimal runnable example (fast) set.seed(123) p <- 1 mu0 <- rep(0, p) deltas <- list(c(3), c(-3)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, 0) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Simulate data with two evenly spaced change points Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) # Run the algorithm out <- FluxPoint(Y, w = 20, tc = 1, max_iter1 = 5, max_iter2 = 5) out$cps # Visualization p1 <- plot_FluxPoint(Y, out$muhats, out$cps, titlename = "", xaxis = "Time") print(p1) ## More realistic example (may take longer) set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(0, -2, 4)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) out <- FluxPoint(Y, w = 20, tc = 1, max_iter1 = 5, max_iter2 = 5) out$cps # Visualization p1 <- plot_FluxPoint(Y, out$muhats, out$cps, titlename = "", xaxis = "Time") print(p1)## Minimal runnable example (fast) set.seed(123) p <- 1 mu0 <- rep(0, p) deltas <- list(c(3), c(-3)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, 0) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Simulate data with two evenly spaced change points Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) # Run the algorithm out <- FluxPoint(Y, w = 20, tc = 1, max_iter1 = 5, max_iter2 = 5) out$cps # Visualization p1 <- plot_FluxPoint(Y, out$muhats, out$cps, titlename = "", xaxis = "Time") print(p1) ## More realistic example (may take longer) set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(0, -2, 4)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) out <- FluxPoint(Y, w = 20, tc = 1, max_iter1 = 5, max_iter2 = 5) out$cps # Visualization p1 <- plot_FluxPoint(Y, out$muhats, out$cps, titlename = "", xaxis = "Time") print(p1)
Implements the core step of the proposed change point
detection (CPD) algorithm to estimate the locations of change points,
given the inverse windowed covariance .
The method computes detector statistics over a moving window using a
projection-based quadratic form and identifies candidate change points
via peak detection.
FluxPoint_raw(data, Sig_all_inv, w, D, needReproduce = FALSE)FluxPoint_raw(data, Sig_all_inv, w, D, needReproduce = FALSE)
data |
Numeric matrix of dimension |
Sig_all_inv |
Numeric matrix of dimension |
w |
Integer; window size used in the moving-window detection step. |
D |
Numeric; detection threshold used in the peak-finding step. |
needReproduce |
Logical; if |
For each center index , a window of width is formed and
contrast vectors are constructed to compare the first and second halves of
the window. Before computing the detector statistic, a component-selection
step is performed using an -penalized regression (lasso, via
glmnet) with weights to identify
variables that exhibit a shift. The resulting active set determines the
projection used in the statistic. Sparse projection matrices indexed by the
active-set pattern are cached and reused for computational efficiency. The
detector statistic is defined as a weighted quadratic form measuring
deviation from the baseline (no-change) projection, and locations at which
the statistic exceeds the threshold D are declared as estimated
change points.
A list with:
'shiftIndices' — Binary matrix () indicating selected
components at each index.
'detectorStats' — Numeric vector of detector values over time.
'Projection_list' — Cache of projection matrices by active-set pattern.
'cps' — Indices of detected change points.
## Minimal runnable example (fast) set.seed(123) p <- 1 mu0 <- rep(0, p) deltas <- list(c(3), c(4)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, 0) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Simulate data with two evenly spaced change points Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) # Windowed covariance and its inverse w <- 20 Sigs <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1) Sig_all_inv <- Sigs$Sig_all_inv # Run detector with a common threshold choice n <- nrow(Y) D <- min(4, log(exp(2) + p)) * log(n - w) res <- FluxPoint_raw(Y, Sig_all_inv, w, D) res$cps ## More realistic example (may take longer) set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(0, -2, 4)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) w <- 20 Sigs <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1) Sig_all_inv <- Sigs$Sig_all_inv n <- nrow(Y) D <- min(4, log(exp(2) + p)) * log(n - w) res <- FluxPoint_raw(Y, Sig_all_inv, w, D) res$cps## Minimal runnable example (fast) set.seed(123) p <- 1 mu0 <- rep(0, p) deltas <- list(c(3), c(4)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, 0) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) # Simulate data with two evenly spaced change points Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) # Windowed covariance and its inverse w <- 20 Sigs <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1) Sig_all_inv <- Sigs$Sig_all_inv # Run detector with a common threshold choice n <- nrow(Y) D <- min(4, log(exp(2) + p)) * log(n - w) res <- FluxPoint_raw(Y, Sig_all_inv, w, D) res$cps ## More realistic example (may take longer) set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(0, -2, 4)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) w <- 20 Sigs <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1) Sig_all_inv <- Sigs$Sig_all_inv n <- nrow(Y) D <- min(4, log(exp(2) + p)) * log(n - w) res <- FluxPoint_raw(Y, Sig_all_inv, w, D) res$cps
Simulates a multivariate time series following the proposed model structure, where the mean component evolves as a random walk with abrupt shifts, overlaid by a stationary VAR(1) process to account for temporal and cross-sectional correlations.
Specifically, at each time point , the data are
generated as
where, for ,
and
Here, denotes the random walk innovation with
covariance , and
is the VAR(1) innovation with covariance
. The vector
is nonzero only at change points.
generate_data( mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype, df = 10, number_cps, lengthofeachpart )generate_data( mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype, df = 10, number_cps, lengthofeachpart )
mu0 |
Numeric vector of length |
deltas |
A list of numeric vectors, each representing the jump
magnitude |
Sig_eta |
Numeric |
Sig_nu |
Numeric |
Phi |
Numeric |
Sig_e1 |
Numeric |
errortype |
Character; either "n" (Gaussian) or "t" (Student's t) specifying the distribution of the innovations. |
df |
Degrees of freedom for the t-distribution (used only when 'errortype = "t"'). Default is 10. |
number_cps |
Integer; number of change points ( |
lengthofeachpart |
Integer; number of observations between
consecutive change points ( |
The total length of the time series is given by
, so that the specified
change points partition the data into equally sized segments. When
, the model reduces to a piecewise
constant mean process with no random walk component. When ,
the process reduces to a random walk model without vector autoregressive
dependence. If both and ,
the model simplifies to the classical piecewise constant setting commonly
used in multiple change point analysis. The two innovation components are
generated independently.
The innovations and are
drawn either from a multivariate normal distribution (when
errortype = "n") using mvrnorm, or from a
multivariate Student's t distribution (when errortype = "t") using
rmvt.
A numeric matrix of dimension , with
, containing the simulated
observations .
set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(-2, 4, 0)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) dim(Y)set.seed(123) p <- 3 mu0 <- rep(0, p) deltas <- list(c(3, 0, -3), c(-2, 4, 0)) Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) Y <- generate_data(mu0, deltas, Sig_eta, Sig_nu, Phi, Sig_e1, errortype = "n", number_cps = 2, lengthofeachpart = 100) dim(Y)
Computes standard evaluation metrics — bias, precision, recall, and F1-score — for change point detection results by comparing estimated change points against true ones within a specified tolerance (acceptance radius).
get_metrics(n, num_cps, est_cps, accept_radius)get_metrics(n, num_cps, est_cps, accept_radius)
n |
Integer; total series length. |
num_cps |
Integer; true number of change points. |
est_cps |
Numeric vector of estimated change point locations. |
accept_radius |
Numeric; tolerance radius within which an estimated change point is considered correctly detected (a true positive). |
True change points are assumed to occur at evenly spaced positions. An
estimated change point is counted as a true positive if it lies within
accept_radius of any true change point location. Estimated points
that do not match any true change point are classified as false positives,
while true change points that are not detected are counted as false
negatives. Bias is defined as the absolute difference between the true and
estimated numbers of change points.
The metrics are defined as:
A list containing:
'bias' — Absolute difference between true and estimated number of change points.
'precision' — Proportion of correctly detected change points among all detections.
'recall' — Proportion of true change points correctly detected.
'F1' — Harmonic mean of precision and recall.
Computes an approximate long-run covariance matrix
for the stationary VAR(1)
process
where has innovation covariance
. The approximation is obtained via a
truncated series expansion up to order 'm'.
get_Sig_e1_approx(Sig_nu, Phi, m = 6)get_Sig_e1_approx(Sig_nu, Phi, m = 6)
Sig_nu |
Numeric |
Phi |
Numeric |
m |
Integer (default = 6). Number of lag terms used in the truncated series expansion. Larger values yield higher accuracy but increase computation time. |
For a stable VAR(1) process, the theoretical long-run covariance satisfies
To avoid matrix inversion, this function approximates the inverse by the truncated Neumann series:
where denotes the Kronecker product of
with itself. The truncation level 'm' controls the
approximation accuracy.
A numeric matrix giving the approximate
.
for observations within a moving windowCalculates the covariance matrix for all
observations within a moving window of length , given the random walk
innovation covariance , the VAR(1) innovation
covariance , the autoregressive coefficient
matrix , and the initial-state covariance matrix
(denoted here by 'Sig_e1').
The resulting matrix accounts for both the random walk component and
the temporal dependence introduced by the VAR(1) structure.
get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1)get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1)
w |
Integer; window size. |
p |
Integer; data dimension. |
Sig_eta |
Numeric |
Sig_nu |
Numeric |
Phi |
Numeric |
Sig_e1 |
Numeric |
The function decomposes the overall covariance matrix
into two additive components corresponding to
the random walk contribution and the
autoregressive contribution , so that
When , the construction reduces to the scalar random walk and
AR(1) case, for which closed-form covariance expressions are available.
For higher-dimensional settings, block-matrix structures are constructed
using functions from the blockmatrix package to capture both
cross-sectional and temporal dependence. The returned inverse matrix
is used in the main change point
detection algorithm to adjust for the effects of random walk drift and
vector autoregressive correlation.
A list with the following components:
'Sig_AR' — Covariance contribution from the VAR(1) component
().
'Sig_RW' — Covariance contribution from the random walk component
().
'Sig_all' — Combined covariance matrix
().
'Sig_all_inv' — Inverse of the combined covariance matrix
.
set.seed(1) p <- 3 w <- 20 Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) res <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1)set.seed(1) p <- 3 w <- 20 Sig_eta <- diag(0.01, p) Sig_nu <- random_Signu(p, 0) Phi <- random_Phi(p, p) Sig_e1 <- get_Sig_e1_approx(Sig_nu, Phi) res <- get_Sigs(w, p, Sig_eta, Sig_nu, Phi, Sig_e1)
Visualizes multivariate time series data together with the estimated fluctuating mean sequence and detected change points obtained from the proposed change point detection (CPD) algorithm. Each variable is plotted in a separate panel (facet), with vertical dashed lines marking detected change points and solid curves showing the estimated means when provided.
plot_FluxPoint(data, muhats, cps, titlename = "", xaxis = "")plot_FluxPoint(data, muhats, cps, titlename = "", xaxis = "")
data |
Numeric matrix of dimension |
muhats |
Optional numeric matrix of the same dimension as 'data',
giving the estimated fluctuating mean sequence
|
cps |
Numeric vector of detected change point locations. |
titlename |
Character string for the plot title. |
xaxis |
Character string for the x-axis label (e.g., "Time"). |
When , the function produces a single plot displaying the
observed time series, the estimated mean curve, and vertical dashed lines
indicating the detected change points. When , each variable is
shown in a separate facet with independently scaled y-axes for improved
readability. If muhats is provided, the estimated mean is overlaid
using geom_line(); otherwise, only the observed data and detected
change points are displayed.
A ggplot2 object displaying the time series, estimated means (if provided), and detected change points.
Generates a autoregressive coefficient matrix
for the VAR(1) component in the proposed model. The diagonal
entries are randomly chosen from {0.5, -0.5}, and a specified number of
off-diagonal elements are randomly assigned nonzero values to introduce
cross-dependence among variables.
random_Phi(p, num_nonzero)random_Phi(p, num_nonzero)
p |
Integer. Dimension of the square matrix ( |
num_nonzero |
Integer. Target number of nonzero off-diagonal
entries in |
The diagonal elements are sampled independently from the set
. Nonzero off-diagonal entries are then placed at random
positions until the total number of nonzero off-diagonal elements reaches
at least num_nonzero. Each nonzero off-diagonal element has magnitude
0.1 or 0.2 with equal probability and a randomly assigned sign. The resulting
matrix governs the temporal dependence of the stationary VAR(1)
process
A numeric matrix representing the autoregressive
coefficient matrix with random diagonal entries in
{0.5, -0.5} and approximately 'num_nonzero' nonzero off-diagonal
elements.
Generates a symmetric innovation covariance matrix
for the VAR(1) component in the proposed
model. The diagonal elements are fixed at 0.5, and a specified number of
off-diagonal elements are randomly assigned nonzero values to introduce
cross-correlation between variables.
random_Signu(p, num_nonzero)random_Signu(p, num_nonzero)
p |
Integer. Dimension of the covariance matrix ( |
num_nonzero |
Integer. Target number of nonzero off-diagonal entries
(counted individually; both upper and lower triangles are included).
Since nonzero values are inserted in symmetric pairs, an even value is
recommended. The maximum meaningful value is |
Each nonzero off-diagonal entry is placed in symmetric pairs
and to ensure symmetry of the matrix. The magnitudes
of the nonzero entries are randomly drawn from the set
with randomly assigned signs. The diagonal entries are
fixed at 0.5 to maintain a moderate level of innovation variance.
In the full model, governs the variability
of the VAR(1) innovation term in
.
A numeric symmetric matrix of dimension representing
with diagonal 0.5 and approximately
'num_nonzero' nonzero off-diagonal entries.