Skip to contents

Performs differencing to remove trends from a zoo time series, isolating short-term fluctuations by subtracting values at specified lags. The function preserves the original index and metadata, with an option to center the output around the mean of the original series. Suitable for preprocessing time series data to focus on random fluctuations unrelated to overall trends.

Usage

f_detrend_difference(x = NULL, lag = 1, center = TRUE, ...)

Arguments

x

(required, zoo object) Zoo time series object to transform.

lag

(optional, integer)

center

(required, logical) If TRUE, the output is centered at zero. If FALSE, it is centered at the data mean. Default: TRUE

...

(optional, additional arguments) Ignored in this function.

Value

zoo object

Examples

x <- zoo_simulate(cols = 2)

y_lag1 <- f_detrend_difference(
  x = x,
  lag = 1
)

y_lag5 <- f_detrend_difference(
  x = x,
  lag = 5
)

if(interactive()){
  zoo_plot(x)
  zoo_plot(y_lag1)
  zoo_plot(y_lag5)
}