Skip to contents

Wraps KWCChangepoint (Ramsay and Chenouri): the functional Kruskal-Wallis covariance test, which ranks observations by statistical depth and segments on the ranks. Because it never touches the values themselves it is insensitive to heavy tails and outlying curves, which is exactly where the moment-based functional tests degrade.

Usage

kwc_wrapper(
  x,
  algorithm = c("fkwc", "dwbs"),
  depth = NULL,
  change_in = c("covariance", "distribution"),
  seed = NULL,
  ...
)

Arguments

x

A numeric matrix or data frame with one row per observation (time point) and one column per grid location or coordinate.

algorithm

"fkwc" (default; pruned exact linear time over the depth ranks) or "dwbs" (depth-based wild binary segmentation).

depth

Depth function. For "fkwc" one of "RPD" (default), "FM", "LTR", "FMd", "RPDd"; for "dwbs" one of "spat", "hs", "mahal", "mahal75".

change_in

Reported change type: "covariance" (default) or "distribution". The test is sensitive to both; this only labels the result.

seed

Optional seed: the random-projection depths and the wild binary segmentation both randomise. The seed is scoped to this call: .Random.seed is saved and restored, so a seeded call inside a simulation loop does not pin the loop's own stream.

...

Additional arguments passed to the engine.

Value

A ggcpt object. Multivariate input is reduced to one series per observation by taking the cross-sectional mean of the columns, and that is the series stored on the result: autoplot() draws it, tidy()'s cp_value reads it, and $segments$param_estimate and augment()'s .fitted/.resid are computed from it. It is not any one column of the input. The full input is kept in $data_wide for autoplot(type = "coordinates").

References

Ramsay K, Chenouri S (2025). “Robust changepoint detection in the variability of multivariate functional data.” Journal of Nonparametric Statistics. doi:10.1080/10485252.2025.2503891 .

Examples

set.seed(2026)
X <- matrix(rnorm(100 * 20), nrow = 100)
X[51:100, ] <- X[51:100, ] * 3
kwc_wrapper(X, seed = 1)
#> ggcpt (changepoint detection result)
#>   Method:             kwc
#>   Change in:          covariance
#>   Changepoints found: 1
#>   CP convention:      left
#>   Penalty:            fkwc
#>   Series length:      100
#> 
#> Changepoints:
#> # A tibble: 1 × 2
#>      cp cp_value
#>   <int>    <dbl>
#> 1    50   -0.240