Performs adaptive trend estimation, cycle detection, Fourier harmonic selection, bootstrap confidence intervals, change points detection, and rolling-origin forecasting. Supports LOESS, GAM, and GAMM models, and handles irregular sampling using the Lomb-Scargle periodogram.
Works with:
dates_type = "date" : Date (daily/weekly/monthly data)
dates_type = "posix" : POSIXct (sub-daily, wearable, EEG, sensors)
dates_type = "numeric": numeric time (spike trains, simulations)
adaptive_cycle_trend_analysis(
signal,
dates,
dates_type = c("date", "posix", "numeric"),
normalize = FALSE,
trendmethod = c("loess", "gam"),
usefourier = FALSE,
fourierK = 2,
auto_fourier_select = TRUE,
fourier_selection_criterion = c("AICc", "BIC"),
fourierK_max = 6,
cimethod = c("model", "bootstrapiid", "bootstrapmbb"),
nboot = 1000,
blocksize = NULL,
seasonalfrequency = 7,
stlrobust = TRUE,
specspans = c(7, 7),
auto_seasonality = TRUE,
lagmax = NULL,
loess_span_mode = c("auto_aicc", "auto_gcv", "cv", "fixed"),
loess_span_fixed = NULL,
loess_span_grid = seq(0.15, 0.6, by = 0.05),
loess_cv_k = 5,
blocklength_mode = c("auto_pwsd", "heuristic", "fixed"),
blocklength_fixed = NULL,
robust = TRUE,
use_gamm = FALSE,
group_var = NULL,
group_values = NULL,
random_effect = NULL,
cor_struct = c("none", "ar1", "arma"),
arma_p = 1,
arma_q = 0,
forecast_holdout_h = 0,
forecast_origin_mode = c("expanding", "sliding"),
train_window = NULL,
forecast_lock_K = TRUE
)A list with:
Data (with PlotDate, timenum, Trend, CI, Outlier)
Trend
CI (lower, upper)
Residuals
Fourier (K)
ChangePoints (in PlotDate scale)
Spectrum
Plot (Trend, Spectrum)
Numeric vector of observed values.
Vector of time indices (Date, POSIXct, or numeric).
"date", "posix", or "numeric".
Logical; if TRUE, Z score normalization is applied.
"loess" or "gam".
Logical; whether to include Fourier harmonics.
Integer; fixed number of harmonics if auto selection disabled.
Logical; if TRUE, selects K via AICc/BIC.
"AICc" or "BIC".
Maximum K to consider during selection.
"model", "bootstrapiid", or "bootstrapmbb".
Number of bootstrap samples.
Block size for MBB bootstrap.
Seasonal frequency for STL (only for dates_type="date").
Logical; robust STL decomposition.
Smoothing spans for spectral estimation.
Logical; if TRUE, uses dominant period.
Maximum lag for ACF and Ljung Box tests.
"auto_aicc", "auto_gcv", "cv", "fixed".
Numeric; fixed LOESS span.
Grid of spans for CV.
Number of folds for blocked CV.
"auto_pwsd", "heuristic", "fixed".
Fixed block length.
Logical; robust LOESS or robust GAM family.
Logical; fit GAMM instead of GAM.
Character; grouping variable for random intercepts.
Optional vector to attach as grouping variable.
Optional random effects list for mgcv::gamm.
"none", "ar1", "arma".
ARMA orders.
Holdout horizon for forecasting.
"expanding" or "sliding".
Training window for sliding origin.
Logical; lock Fourier K across origins.