| smooth_outlier | R Documentation |
Identify outliers in a numeric time series and replace them with smoothed values.
smooth_outlier(x, periods, ...)
x |
Numeric vector containing the time series observations. |
periods |
Numeric vector giving the seasonal periods of the time series,
for example |
... |
Further arguments passed to |
smooth_outlier() is a small wrapper around
forecast::tsoutliers(). The input vector is first converted to an
msts object using the seasonal periods supplied in periods.
For non-seasonal time series, forecast::tsoutliers() uses a
supsmu-based approach. For seasonal time series, the series is
decomposed using STL and outliers are identified on the remainder component.
Detected outliers are replaced by the replacement values returned by
forecast::tsoutliers().
The function returns a plain numeric vector with the same length as the input.
A numeric vector where detected outliers are replaced by smoothed values.
Other data preparation:
check_data(),
interpolate_missing()
library(dplyr)
x <- M4_monthly_data |>
filter(series == first(series)) |>
pull(value)
x_outlier <- x
x_outlier[20] <- x_outlier[20] * 5
x_smoothed <- smooth_outlier(
x = x_outlier,
periods = 12
)
x_outlier[20]
x_smoothed[20]
hourly <- elec_price |>
filter(bidding_zone == "DE") |>
slice_head(n = 24 * 14) |>
pull(value)
hourly_outlier <- hourly
hourly_outlier[48] <- hourly_outlier[48] * 5
smooth_outlier(
x = hourly_outlier,
periods = c(24, 168)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.