This R is the assignment of week 2 discussion for the course of Predictive Analytics. The task is : Pick a time series that has monthly data and conduct additive and multiplicative decomposition. (You cannot decompose daily data!) Which one worked better? How can you tell? How would you use the results in forecasting (or would you?)?
The purpose of this section is to preprocess and describe the dataset. The dataset used was the Monthly Sunspot Dataset, This dataset describes a monthly count of the number of observed sunspots for just over 230 years (1749-1983). Here is a first view of the data.
data <- read.csv("https://raw.githubusercontent.com/jbrownlee/Datasets/master/monthly-sunspots.csv")
summary(data)
## Month Sunspots
## Length:2820 Min. : 0.00
## Class :character 1st Qu.: 15.70
## Mode :character Median : 42.00
## Mean : 51.27
## 3rd Qu.: 74.92
## Max. :253.80
Inicially we plot the time serie.
The additive approach is based in
dec1<-decompose(data,type="additive") #build an additive decomposition model
plot(dec1)
The additive approach is based in
dec2<-decompose(data,type="multiplicative") #build a multiplicative decomposition model
plot(dec2)
#Decompose the time series
data2 <- stl(data, s.window="periodic", robust=TRUE)
plot(data2)
fit <- seas(x = data, x11 = "")
autoplot(fit)