Decomposition of Series

An Observed time series is made of three components 1. trend 2. Seasonal effect 3. Error Term Here we find how we can extract trend and seasonal effect Simple additive decomposition model is: x = trend + season + error Simple Multiplicative decomposition model is: x = trenx x season + error Trend: is calculated using Moving average

Decompose: Estimate Trend and Seasonal Effect using MA

Below command done to load all the variables in the Global Environment. Needed for RMarkdown

load("workspace.RData")
plot(decompose(Elec.ts))

By default the above model is additive. We can go for multiplicative model by using type=“mult”

Elec.decom <- decompose(Elec.ts,type="mult")
plot(Elec.decom)

We can see that in multiplicative case, the random terms are more random as compared to the additive case. Lets see the structure of Elec.decom

str(Elec.decom)
## List of 6
##  $ x       : Time-Series [1:396] from 1958 to 1991: 1497 1463 1648 1595 1777 1824 1994 1835 1787 1699 ...
##  $ seasonal: Time-Series [1:396] from 1958 to 1991: 0.909 0.891 0.97 0.938 1.051 ...
##  $ trend   : Time-Series [1:396] from 1958 to 1991: NA NA NA NA NA ...
##  $ random  : Time-Series [1:396] from 1958 to 1991: NA NA NA NA NA ...
##  $ figure  : num [1:12] 0.909 0.891 0.97 0.938 1.051 ...
##  $ type    : chr "multiplicative"
##  - attr(*, "class")= chr "decomposed.ts"

Here figure is the estimated seasonal index. Here we can segregare the trend and seasonal components and then plot only these two ( leaving random component one over the other. We use lty to change the line type). We use ts.plot to plot the graph so that they superimpose over each other.

Trend <- Elec.decom$trend
Seasonal <- Elec.decom$seasonal
ts.plot(cbind(Trend,Trend*Seasonal),lty=1:2)

lets Understand the class of Trend ( and hence seasonality)

class(Trend)
## [1] "ts"

Below command done to save all the variables in the Global Environment. Needed for RMarkdown

save.image("workspace.Rdata")