In Kuhn and Johnson do problems 6.2 and 6.3. There are only two but they consist of many parts. Please submit a link to your Rpubs and submit the .rmd file as well.
## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 1 742 697 776 898 1030 1107 1165 1216 1208 1131 971 783
## 2 741 700 774 932 1099 1223 1290 1349 1341 1296 1066 901
## 3 896 793 885 1055 1204 1326 1303 1436 1473 1453 1170 1023
## 4 951 861 938 1109 1274 1422 1486 1555 1604 1600 1403 1209
## 5 1030 1032 1126 1285 1468 1637 1611 1608 1528 1420 1119 1013
plastics_df <- data.frame(
Month = time(plastics),
Sales = as.numeric(plastics)
)
write.csv(plastics_df, "plastics.csv", row.names = FALSE)## null device
## 1
autoplot(plastics) +
labs(title = "Monthly sales of product A (plastics)",
x = "Year", y = "Sales (thousands)")The time series shows clear seasonal fluctuations because the sales rise and fall in a repeating pattern from year to year (a regular 12-month cycle typical of monthly data). At the same time, there is also a trend-cycle component, because the overall level of sales changes across the five-year period, with sales generally increasing even though they continue to move up and down due to seasonality.
## Jan Feb Mar Apr May Jun Jul
## 1 NA NA NA NA NA NA 976.9583
## 2 1000.4583 1011.2083 1022.2917 1034.7083 1045.5417 1054.4167 1065.7917
## 3 1117.3750 1121.5417 1130.6667 1142.7083 1153.5833 1163.0000 1170.3750
## 4 1208.7083 1221.2917 1231.7083 1243.2917 1259.1250 1276.5833 1287.6250
## 5 1374.7917 1382.2083 1381.2500 1370.5833 1351.2500 1331.2500 NA
## Aug Sep Oct Nov Dec
## 1 977.0417 977.0833 978.4167 982.7083 990.4167
## 2 1076.1250 1084.6250 1094.3750 1103.8750 1112.5417
## 3 1175.5000 1180.5417 1185.0000 1190.1667 1197.0833
## 4 1298.0417 1313.0000 1328.1667 1343.5833 1360.6250
## 5 NA NA NA NA NA
## [1] 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
## [8] 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
seasonal_table <- data.frame(
Month = month.abb,
SeasonalIndex = as.numeric(seasonal_idx)
)
seasonal_table## Month SeasonalIndex
## 1 Jan 0.7670466
## 2 Feb 0.7103357
## 3 Mar 0.7765294
## 4 Apr 0.9103112
## 5 May 1.0447386
## 6 Jun 1.1570026
## 7 Jul 1.1636317
## 8 Aug 1.2252952
## 9 Sep 1.2313635
## 10 Oct 1.1887444
## 11 Nov 0.9919176
## 12 Dec 0.8330834
Yes. The decomposition confirms the same pattern: a clear repeating seasonal cycle and a smoother trend-cycle over time, matching what the plot showed.
fit <- decompose(plastics, type = "multiplicative")
plastics_sa <- plastics / fit$seasonal
autoplot(plastics_sa) +
labs(title = "Seasonally Adjusted Sales (Product A)",
x = "Year", y = "Sales (thousands)")
## E.Change one observation to be an outlier (e.g., add 500 to one
observation), and recompute the seasonally adjusted data. What is the
effect of the outlier?
plastics_out <- plastics
plastics_out[20] <- plastics_out[20] + 500 # create an outlier
fit_out <- decompose(plastics_out, type = "multiplicative")
plastics_sa_out <- plastics_out / fit_out$seasonal
autoplot(plastics_sa_out) +
labs(title = "Seasonally Adjusted Sales with an Outlier",
x = "Year", y = "Sales (thousands)")
Adding an outlier creates a large spike in the seasonally adjusted
series and also distorts the estimated trend-cycle and seasonal pattern
around that time. Even though only one observation is changed, nearby
values are affected, showing that classical multiplicative decomposition
is sensitive to outliers.
Yes. An outlier near the end has a larger impact on the results because there are fewer neighboring observations to smooth it out, which makes the estimated trend-cycle and seasonal adjustment more distorted at the boundary than when the outlier is in the middle of the series.
retail_ts <- ts(dat$sales, frequency = 12, start = c(2018, 1))
fit_x11 <- seas(retail_ts, x11 = "")
plot(fit_x11)
outliers(fit_x11)I decomposed the retail series using X-11 and checked the output for unusual spikes or drops. The X-11 results (especially the irregular component and the outlier table) show whether any months behave unusually after removing trend and seasonality; if outliers are listed, those months are clear anomalies, and if none are listed, then the series does not show strong outliers beyond normal variation.