Skip to contents

Wraps fChange::fchange() for changes in the mean function of a functional time series: each observation is a curve, and the question is when the average curve shape changes. The binary-segmentation ("segmentation") mode finds multiple changes; the "single" mode runs the one-change test and reports its p-value.

Usage

fmean_wrapper(
  x,
  statistic = c("Tn", "Mn"),
  critical = c("simulation", "resample", "welch"),
  type = c("segmentation", "single"),
  alpha = 0.05,
  robust = FALSE,
  ...
)

Arguments

x

A numeric matrix or data frame with one row per time point and one column per grid location (the curve's resolution).

statistic

Test statistic: "Tn" (integrated, the default) or "Mn" (maximum).

critical

How critical values are obtained: "simulation" (default), "resample" or "welch". The first two draw random numbers and there is no seed argument, so call set.seed() first when the answer has to be reproducible.

type

"segmentation" (default, multiple changes) or "single" (one change).

alpha

Significance level. Defaults to 0.05.

robust

Use the robust ("robustmean") statistic instead of the classical mean one? Defaults to FALSE.

...

Additional arguments passed to fChange::fchange().

Value

A ggcpt object; the changepoints tibble carries the engine's p_value for each location. 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

Aue A, Rice G, Sönmez O (2018). “Detecting and dating structural breaks in functional data without dimension reduction.” Journal of the Royal Statistical Society: Series B, 80(3), 509–529. doi:10.1111/rssb.12257 .

Examples

# \donttest{
set.seed(2026)
# 10 curves and M = 50, not 20 and 200: the example is a demonstration,
# and the wider version measured 6.7 s against CRAN's 5 s budget.
X <- matrix(rnorm(60 * 10), nrow = 60)
X[31:60, ] <- X[31:60, ] + 2
fmean_wrapper(X, M = 50)
#> ggcpt (changepoint detection result)
#>   Method:             fmean
#>   Change in:          mean
#>   Changepoints found: 1
#>   CP convention:      left
#>   Penalty:            alpha = 0.05
#>   Series length:      60
#> 
#> Changepoints:
#> # A tibble: 1 × 3
#>      cp cp_value p_value
#>   <int>    <dbl>   <dbl>
#> 1    30    0.439       0
# }