| stick | R Documentation |
The function decomposes the variance of a time series into seasonal, trend and irregular parts based on an Analysis of Variance (ANOVA) of the series on the seasonal and trend factors and measures their contribution to the data.
stick(y, lags = frequency(y), ...)
## S3 method for class 'stick'
print(x, digits = 4, ...)
## S3 method for class 'stick'
plot(x, which = NULL, ask, ...)
y |
The vector or a ts object, containing the time series to analyse. |
lags |
The vector of seasonal lags (periodicities) in the data, e.g.
|
... |
Other parameters passed to the |
x |
The object of class "stick" generated by the |
digits |
The number of digits to use when printing the strength of the components. |
which |
The vector of integers specifying which plots to produce: the
values |
ask |
Logical; if |
stick() forms internally a data frame with the response y in
the first column, a categorical (factor) variable for each of the provided
seasonal lags and a "trend" factor in the last column. For a monthly
series with lags=12, the seasonal factor takes values 1:12
repeated throughout the sample (the month of the year), while the trend
factor takes values 1:ceiling(T/12), each repeated 12 times (the
year). The trend factor is constructed based on the longest of the provided
lags.
aov() is then applied to the model y ~ seasonal + trend and the
strength of each component is measured as the share of the respective Sum of
Squares in the total Sum of Squares. The irregular component corresponds to
the share of the residual Sum of Squares. The strengths of all the components
sum up to one.
The function implements the Seasonality, Trend, and Irregular (STI) classification of Hans Levenbach (see the reference below).
plot.stick() reproduces two types of plots, in the spirit of the STI
decomposition. For every seasonal lag it draws a "seasonal plot": the series
is reshaped into a matrix with one column per cycle (e.g. per year for
monthly data) and the value within the cycle on the x-axis; each cycle is a
grey line and the average seasonal profile (the mean across the cycles) is
overlaid as a bold dashed black line. The final plot is the "trend plot",
which uses the longest lag: each seasonal position (e.g. each month) is a
grey line drawn across the cycles, and the average level per cycle (the
trend) is overlaid as a bold dashed black line.
stick() returns an object of class "stick", which contains:
y - The original data;
lags - The seasonal lags used in the analysis;
model - The fitted aov model;
anova - The ANOVA table (the first element of summary(model));
strength - The named vector with the strength of each seasonal component, the trend and the irregular component. The values sum up to one.
plot.stick() is called for its side effect of producing the
plots and returns NULL invisibly.
Ivan Svetunkov, ivan@svetunkov.com
Levenbach, H. (2021). Four P's in a Pod: e-Commerce Forecasting and Planning for Supply Chain Practitioners. Independently published. ISBN 979-8461733575.
aov
# Generate a seasonal series and classify it
y <- ts(rnorm(120, 100 + 20 * sin(2 * pi * (1:120) / 12), 5), frequency=12)
stick(y)
# Produce all the plots
par(mfcol=c(1,2))
plot(stick(AirPassengers))
# Only the trend plot
plot(stick(AirPassengers), which=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.