Homework Assignment 3
6.2
?plasticsplastics## 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
a.
plot(plastics, ylab="Sales (Thousands)", xlab="Year", main="Plastics Yearly Sales Time Plot")The graph shows us that there is a seasonal trend, with an overall upward trend to the data. There is a clear drop in sales at the beginning of each year. ####b.
model<- plot(decompose(plastics, type="multiplicative"))model## NULL
calc <- decompose(plastics)
calc$figure## [1] -273.203993 -339.933160 -263.099826 -104.943576 56.504340
## [6] 193.316840 183.441840 254.952257 265.316840 221.139757
## [11] -4.953993 -188.537326
c.
yes, we can see from the trend graph that there is an increase in sales overtime. From the seasonal graph, we can see the seasonality in each of the 5 years. In the random graph, we can see some randomness in the residuals.
d.
autoplot(plastics, series="Data") +
autolayer(trendcycle(calc), series="Trend") +
autolayer(seasadj(calc), series="Seasonally Adjusted") +
xlab("Year") + ylab("Monthly Sales amount") +
ggtitle("Sales of plastic product (in thousand)") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))## Warning: Removed 12 rows containing missing values (geom_path).
e.
plastics[30]=plastics[30]+500
model<-decompose(plastics, type="multiplicative")
tr<-model$trend
seas<- model$seasonal
plot(seasadj(model)) The outlier caused a significant change in the graph when it was added. ####f.
plastics[60]=plastics[60]+500
model<-decompose(plastics, type="multiplicative")
tr<-model$trend
seas<- model$seasonal
plot(seasadj(model))The graph has less variance if the outlier is added to the end of the data. But it does cause a significant spike at the end of the series when added.
6.3
retaildata <- readxl::read_excel('retail.xlsx', skip = 1)## readxl works best with a newer version of the tibble package.
## You currently have tibble v1.4.2.
## Falling back to column name repair from tibble <= v1.4.2.
## Message displays once per session.
myts <- ts(retaildata[,'A3349399C'], frequency = 12, start = c(1982,4))
autoplot(myts)x11_retail <- seas(myts, x11 = "")
autoplot(x11_retail) In the remainders plot, I can see some outliers around the year 2001 that I had not noticed prior to plotting this. I can also spot a variance in the seasonality around that time. The trend plot is as I had expected, with an increase over time.