View source: R/deseason_series.R
| deseason_series | R Documentation |
Pipe-friendly convenience wrapper around decompose_series() focused on a
single task: removing the seasonal component from a time series. It adds a
seasadj_{method} column holding the seasonally adjusted (deseasoned) series
and, optionally, the underlying trend, seasonal, and remainder components.
deseason_series(
data,
date_col = "date",
value_col = "value",
group_cols = NULL,
methods = "stl",
transform = "none",
frequency = NULL,
components = FALSE,
params = list(),
.quiet = FALSE
)
data |
A |
date_col |
Name of the date column. Defaults to |
value_col |
Name of the value column. Defaults to |
group_cols |
Optional grouping variables for multiple time series. A character vector of column names. When provided, decomposition is applied independently to each group. |
methods |
Seasonal-adjustment method(s). One or more of
|
transform |
Transformation applied to the series before decomposition.
One of |
frequency |
The frequency of the series. Must be greater than 1;
|
components |
If |
params |
Optional list of method-specific parameters for fine control. Every parameter has a default, so this argument is only needed for non-standard use cases. For STL (
For regression (
classic, bsm, and seats take no |
.quiet |
If |
deseason_series() is a thin wrapper: it calls decompose_series() with
seasadj = TRUE and then keeps only the seasonally adjusted column unless
components = TRUE. All seasonal-adjustment behaviour, validation, grouping,
and the transform = "log" (multiplicative) path are inherited unchanged
from decompose_series(). See its documentation for method internals and the
meaning of the params argument.
For a full trend/seasonal/remainder decomposition, or for the regression,
classic, and bsm methods, use decompose_series() directly.
A tibble with the original columns plus, for each requested method, a
seasadj_{method} column holding the seasonally adjusted series. When
components = TRUE, the trend_{method}, seasonal_{method}, and
remainder_{method} columns are added as well.
The seasonally adjusted series is the series with the seasonal component
removed: trend + remainder for additive decompositions, trend * remainder when transform = "log". Output rows come back in the order
they were supplied in.
decompose_series() for the underlying decomposition and the full
set of methods; augment_trends() to extract a trend component only.
# Seasonally adjust a quarterly series (STL, the default)
gdp_construction |>
deseason_series(value_col = "index")
# Also keep the trend, seasonal, and remainder components
gdp_construction |>
deseason_series(value_col = "index", components = TRUE)
# Multiplicative adjustment via log transform (seasonal swings grow with level)
gdp_construction |>
deseason_series(value_col = "index", transform = "log")
# X-13ARIMA-SEATS adjustment (requires the 'seasonal' package)
if (requireNamespace("seasonal", quietly = TRUE)) {
gdp_construction |>
deseason_series(value_col = "index", methods = "seats")
}
# Compare STL and SEATS adjustments side by side
if (requireNamespace("seasonal", quietly = TRUE)) {
gdp_construction |>
deseason_series(value_col = "index", methods = c("stl", "seats"))
}
# Grouped seasonal adjustment: one adjustment per electricity sector
electricity |>
deseason_series(group_cols = "name_series")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.