library(timeSeries)
## Loading required package: timeDate
#loading the “cbe.dat” file 
CBE <- read.table("cbe.dat", header = T)
#see the first six rows of the dataset
head(CBE)
##   choc beer elec
## 1 1451 96.3 1497
## 2 2037 84.4 1463
## 3 2477 91.2 1648
## 4 2785 81.9 1595
## 5 2994 80.5 1777
## 6 2681 70.4 1824
#1.Produce a time plot of the data.  Plot the aggregated annual series and a boxplot 
#that summarizes the observed values for each season.Comment on the plots.
#convert the dataset class to timeseries class
cbe.month.ts <- ts(CBE,start = c(1958,1),end = c(1990,12),frequency = 12)
cbe.annual.ts <- aggregate(cbe.month.ts, FUN=mean)
plot(cbe.month.ts,xlab="Time",ylab="monthly supply of electricity (millions of kWh), beer (Ml), and chocolate")

plot(cbe.annual.ts,xlab="Time",ylab="monthly supply of electricity (millions of kWh), beer (Ml), and chocolate")

boxplot(cbe.month.ts~cycle(cbe.month.ts))

#Peak months are May and July beause of the summers and least month January because of the
#winter.

#2.Decompose the series into the components trend, seasonal effect, and residuals, and plot the decomposed series.
#Produce a plot of the trend with a superimposed seasonal effect.
Elec.ts <- ts(CBE[, 3], start = 1958, freq = 12)
Beer.ts <- ts(CBE[, 2], start = 1958, freq = 12)
Choc.ts <- ts(CBE[, 1], start = 1958, freq = 12)
#decomposition of electricity
Elec.decom1 <- decompose(Elec.ts, type = "mult")
plot(Elec.decom1)

#decomposition of Beer
Elec.decom2 <- decompose(Beer.ts, type = "mult")
plot(Elec.decom2)
#decomposition of chocolate
Elec.decom3 <- decompose(Beer.ts, type = "mult")
plot(Elec.decom3)