Two-sided Centered Moving Average Smoother
ma.RdApplies a centered moving average filter to a time series using either a rectangular window
(default) or a custom window function. If a user-supplied window function is provided via
w.func, it will be called as w.func(order, ...) and must return a numeric vector
of length order.
Arguments
- ts
A `ts` object to be smoothed.
- order
An integer specifying the moving average window size. Must be ≥ 1.
- na.rm
Logical. If `TRUE` (default), removes `NA` values introduced by filtering.
- w.func
Optional function to generate a weight vector given `order`. Should return a numeric vector of length `order`.
- ...
Additional arguments passed to `w.func`, if specified.
Value
A smoothed `ts` object with attributes:
collectorSet to `"single"` for bookkeeping.
q_orderThe order of the moving average used.
Examples
if (FALSE) { # \dontrun{
ts_data <- ts(rnorm(100))
ma(ts_data, order = 5)
# Using a Tukey window
if (requireNamespace("bspec", quietly = TRUE)) {
ma(ts_data, order = 11, w.func = tukey_window, r = 0.3)
}
} # }