Decomposes a seasonal time series into trend, seasonal and remainder components and shows them, with the original series, as stacked panels.
Usage
decompose_plot(
x,
frequency = NULL,
method = c("stl", "classical"),
robust = FALSE,
confidence = FALSE,
level = 0.95,
title = NULL
)Arguments
- x
A
tsobject, or a numeric vector (thenfrequencyis required).- frequency
Number of observations per period (e.g. 12 for monthly data); taken from
xwhen it is ats.- method
"stl"(loess-based) or"classical"(stats::decompose()).- robust
For
method = "stl", whether to fit a robust STL (stats::stl()withrobust = TRUE), which down-weights outliers in the loess fits so that an unusual point bleeds less into the trend and seasonal components. Ignored for the classical method.- confidence
Whether to draw a confidence ribbon around the trend component. The band is a normal-approximation interval based on the remainder's standard deviation (see Details).
FALSEreproduces the previous behaviour exactly.- level
Coverage of the trend confidence ribbon (a single number strictly between 0 and 1).
- title
Plot title.
Value
A 'patchwork' object (printable like a ggplot2::ggplot).
Details
The trend confidence ribbon is a pragmatic normal-approximation band:
trend +/- z * sd(remainder), where z = qnorm((1 + level) / 2) and the
remainder standard deviation is computed on the non-missing remainder values.
It conveys the scale of the unexplained variation around the smoothed trend
rather than a formal sampling-distribution interval.



