D. Plot seasonally adjusted
- Use all measures of decomposition to graph out seasonally adjusted data
- I only show the code for first plot as its repetitive
autoplot(plastics, series="Data") +
autolayer(trendcycle(multiplicative_plastics), series="Trend") +
autolayer(seasadj(multiplicative_plastics), series="Seasonally Adjusted") +
xlab("Year") + ylab("New orde index") +
ggtitle("Seasonal adjust with multiplicative decomp")+
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))
## Warning: Removed 12 rows containing missing values (geom_path).

## Warning: Removed 12 rows containing missing values (geom_path).




How is our seasonality changing over time
- lets take a look at the subseries plots
a <- additive_plastics %>% seasonal() %>% ggsubseriesplot() + ylab("Seasonal")+ggtitle("Seasonal adj w additive decomp")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
b <- multiplicative_plastics %>% seasonal() %>% ggsubseriesplot() + ylab("Seasonal")+ggtitle("Seasonal adjust with multi decomp")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
c <- Seats_decomposition%>% seasonal() %>% ggsubseriesplot() + ylab("Seasonal")+ggtitle("Seasonal adjust with seats decomp")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
d <- stl_decomposition%>% seasonal() %>% ggsubseriesplot() + ylab("Seasonal")+ggtitle("Seasonal adjust with stl decomp")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
e <- x_11_decomp%>% seasonal() %>% ggsubseriesplot() + ylab("Seasonal")+ggtitle("Seasonal adjust with x-11 decomp")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
plot_grid(a,b)



- It seems that the year to year variations in seasonality, are removed in the Stl, additive and multiplicative models. There is some variation in the Seats, and x-11 decomp
E/F: 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?
- From what I can tell in multiplicative model, outliers at the beginning of the model have less effect than outliers in the middle and in the end. Outliers in the middle, seem to throw off our adjustments by a similar level at intervals of exactly one year throughout the timeseries.
plastics <- fma::plastics
new_plastics <- plastics
new_plastics[3] <- 1200
plastics
## 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
new_plastics <- ts(new_plastics,start= 2000, frequency = 12)
multiplicative_plastics_w_outlier <- new_plastics %>% decompose(type="multiplicative")
autoplot(new_plastics, series="Data") +
autolayer(seasadj(multiplicative_plastics_w_outlier), series="Seasonally Adjusted_outlier") +
autolayer(seasadj(multiplicative_plastics), series="Seasonally Adjusted") +
xlab("Year") + ylab("New orde index") +
ggtitle("Seasonal adjust with multiplicative decomp outlier at start")+
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

## 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

## 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

## 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


## [1] 12
# new_plastics <- plastics
# new_plastics[30] <- 1900
# plastics
# new_plastics <- ts(new_plastics,start= 2000, frequency = 12)
# multiplicative_plastics_w_outlier <- new_plastics %>% decompose(type="multiplicative")
# autoplot(new_plastics, series="Data") +
# autolayer(seasadj(multiplicative_plastics_w_outlier), series="Seasonally Adjusted_outlier") +
# autolayer(seasadj(multiplicative_plastics), series="Seasonally Adjusted") +
# xlab("Year") + ylab("New orde index") +
# ggtitle("Seasonal adjust with multiplicative decomp outlier in middle")+
# scale_colour_manual(values=c("gray","blue","red"),
# breaks=c("Data","Seasonally Adjusted","Trend"))
#
# new_plastics <- plastics
# new_plastics[30] <- 1900
# plastics
# new_plastics <- ts(new_plastics,start= 2000, frequency = 12)
# multiplicative_plastics_w_outlier <- new_plastics %>% decompose(type="multiplicative")
# autoplot(new_plastics, series="Data") +
# autolayer(seasadj(multiplicative_plastics_w_outlier), series="Seasonally Adjusted_outlier") +
# autolayer(seasadj(multiplicative_plastics), series="Seasonally Adjusted") +
# xlab("Year") + ylab("New orde index") +
# ggtitle("Seasonal adjust with multiplicative decomp outlier in middle")+
# scale_colour_manual(values=c("gray","blue","red"),
# breaks=c("Data","Seasonally Adjusted","Trend"))