Number 1
library(fpp2)
## Warning: package 'fpp2' was built under R version 3.4.4
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.4.3
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.4.4
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.4.4
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 3.4.4
library(readxl)
## Warning: package 'readxl' was built under R version 3.4.3
data <- read_xlsx("C:/Users/buffe/Documents/Forecasting Principles/Retail Data.xlsx", skip = 1)
ts1 <- ts(data[,3], start = c(1982, 4), deltat = 1/12)
autoplot(ts1)
library(seasonal)
## Warning: package 'seasonal' was built under R version 3.4.4
fit <- seas(ts1, x11="")
autoplot(fit)
Number 2
data <- cangas
autoplot(data)
ggsubseriesplot(data)
ggseasonplot(data)
stl.data <- stl(data, s.window = "periodic", robust=TRUE)
x11.data <- seas(data, x11 = "")
seats.data <- seas(data)
autoplot(stl.data)
autoplot(x11.data)
autoplot(seats.data)
I think that the seaaonality is changing do to supply and demand in the market. The SEATS and X11 differ by the remainder graph. The X11 has more data points that deiviate further away from one.
Number 3
data <- oil
ma.data <- ma(data,6)
autoplot(data, series = "Data") +
autolayer(ma.data, series = "5-MA") +
xlab("Year") + ylab("GWh") +
scale_colour_manual(values=c("Data"="grey50", "5-MA"="red"),
breaks=c("Data","5-MA"))
## Warning: Removed 6 rows containing missing values (geom_path).
Number 4
data <- plastics
autoplot(plastics)
de.data <- decompose(plastics, type = "multiplicative")
autoplot(de.data)
autoplot(seasadj(de.data))
data.out.mid <- plastics
data.out.mid[25] <- data.out.mid[25] + 500
autoplot(seasadj(decompose(data.out.mid, type = "multiplicative")))
data.out.end <- plastics
data.out.end[55] <- data.out.end[55] + 500
autoplot(seasadj(decompose(data.out.end, type = "multiplicative")))
Number 5
data <- fancy
autoplot(data)
fit <- stlf(fancy, method = "rwdrift", lambda = BoxCox.lambda(fancy))
autoplot(fit)
data2 <- writing
autoplot(data2)
fit2 <- stlf(data2, method = "naive")
autoplot(fit2)