plastics
data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.autoplot(plastics) + scale_y_continuous(labels=comma) +
labs(title='Monthly Sales of Plastic Product "A"',
y="Sales", x="Time")
ggseasonplot(plastics) +
labs(y="Sales", x="Month") +
guides(colour=guide_legend(title="Year"))
ggsubseriesplot(plastics) +
labs(title='Subseries Plot',
y="Sales", x="Month")
Looking at these plots, there is definitely a seasonality. Sales picks up in April, peaks near August, then then declines.
There is also a trend, shown in the Seasonal Plot, where sales have been increasing each year. However, there appears to be something in the 5th year causing a premature decline in June and a decrease by year-end lower than it began. This may indicate that the upward trend is about to reverse.
decomp <- decompose(plastics, type="multiplicative")
autoplot(decomp) + labs(title="Classic Multiplicative Decomposition",
x="Time")
sadjust <- seasadj(decomp)
autoplot(sadjust) + scale_y_continuous(labels=comma) +
labs(title='Monthly Sales of Plastic Product "A"',
subtitle = "Seasonally-adjusted (Classic Multiplicative)",
y="Sales", x="Time")
# Change Aug in Year 5
plastics2 <- plastics
plastics2[length(plastics2)-4] <- plastics[length(plastics)-4]+500
decomp2 <- decompose(plastics2, type="multiplicative")
sadjust2 <- seasadj(decomp2)
autoplot(sadjust2) + scale_y_continuous(labels=comma) +
labs(title='Monthly Sales of Plastic Product "A"',
subtitle = "Seasonally-adjusted (End Outlier)",
y="Sales", x="Time")
# Change Jun in year 3 to compare an outlier in the middle
plastics3 <- plastics
plastics3[length(plastics2)-30] <- plastics[length(plastics)-30]+500
decomp3 <- decompose(plastics3, type="multiplicative")
sadjust3 <- seasadj(decomp3)
autoplot(sadjust3) + scale_y_continuous(labels=comma) +
labs(title='Monthly Sales of Plastic Product "A"',
subtitle = "Seasonally-adjusted (Middle Outlier)",
y="Sales", x="Time")
# Load the retail data
# A3349414R series ("Turnover ; Victoria ; Liquor retailing ;")
retail <- readxl::read_xlsx("retail.xlsx",skip=1)
myts <- ts(retail[,"A3349414R"], frequency = 12, start = c(1982,4))
# Initial plot of the data
autoplot(myts) +
labs(title="Liquor Retailing Turnover",subtitle="Victoria") +
xlab("Date") + ylab("Turnover")
myts.decomp <- myts %>% seas(x11="")
autoplot(myts.decomp)
The X-11 decomposition shows that the seasonality pattern is mostly unchanged throughout the timeframe, but the amplitude of the larger part of the annual seasonal swing increases from 1985 through about 2001 when it then begins to decrease a bit so the seasonal component is not adding as much.
In terms of outliers, this decomposition doesn’t show anything glaring in the data.