View source: R/diagnostics-tk_stl_diagnostics.R
| tk_stl_diagnostics | R Documentation |
tk_stl_diagnostics() is the preprocessor for plot_stl_diagnostics().
It helps by automating frequency and trend selection.
tk_stl_diagnostics(
.data,
.date_var,
.value,
.frequency = "auto",
.trend = "auto",
.message = TRUE
)
.data |
A |
.date_var |
A column containing either date or date-time values |
.value |
A column containing numeric values |
.frequency |
Controls the seasonal adjustment (removal of seasonality).
Input can be either "auto", a time-based definition (e.g. "2 weeks"),
or a numeric number of observations per frequency (e.g. 10).
Refer to |
.trend |
Controls the trend component. For STL, trend controls the sensitivity of the lowess smoother, which is used to remove the remainder. |
.message |
A boolean. If |
The tk_stl_diagnostics() function generates a Seasonal-Trend-Loess decomposition.
The function is "tidy" in the sense that it works
on data frames and is designed to work with dplyr groups.
STL method:
The STL method implements time series decomposition using
the underlying stats::stl(). The decomposition separates the
"season" and "trend" components from
the "observed" values leaving the "remainder".
Frequency & Trend Selection
The user can control two parameters: .frequency and .trend.
The .frequency parameter adjusts the "season" component that is removed
from the "observed" values.
The .trend parameter adjusts the
trend window (t.window parameter from stl()) that is used.
The user may supply both .frequency
and .trend as time-based durations (e.g. "6 weeks") or numeric values
(e.g. 180) or "auto", which automatically selects the frequency and/or trend
based on the scale of the time series.
A tibble or data.frame with Observed, Season, Trend, Remainder,
and Seasonally-Adjusted features
library(dplyr)
# ---- GROUPS & TRANSFORMATION ----
m4_daily %>%
group_by(id) %>%
tk_stl_diagnostics(date, box_cox_vec(value))
# ---- CUSTOM TREND ----
m4_weekly %>%
group_by(id) %>%
tk_stl_diagnostics(date, box_cox_vec(value), .trend = "2 quarters")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.