library(readxl, quietly = TRUE, warn.conflicts =  FALSE, verbose = F)
library(fpp2,quietly = TRUE, warn.conflicts =  FALSE, verbose = F)

Q1 Excercise 2.1

2.1a

  gold contains daily morning gold prices in US dollars. 1 January 1985 – 31 March. The plot 
  below shows, gold was in an uptrend until around '670' followed by a downward trend. 
    
autoplot(gold)

woolyrnq contains quarterly production of woollen yarn in Australia from Mar 1965 – Sep 1994.
autoplot(woolyrnq)

gas contains Australian monthly gas production: 1956–1995. Plot below shows clear uptrend in gas production from 1970.
autoplot(gas)

2.1b Frequency

gold frequency is 1

gas frequency is 12

woolyrnq frequency is 4

2.1b Outlier

Outlier in gold series is 770

Q2 Excercise 2.2

tute1 <- read.csv("tute1.csv", header=TRUE)

tseries <- ts(tute1[,-1], start=1981, frequency=4)
head(tute1)
autoplot(tseries, facets=TRUE)

autoplot(tseries)

If facets parameter is specified with TRUE, then each variable is plotted on a separate panel with its own scale. If it is not specified or set to False, then all variables are plotted in one plot.

Q3 Excercise 2.3

Read excel data and display first few records

retaildata <- readxl::read_excel("retail.xlsx", skip=1)
head(retaildata)

Select Liquor retail data for time series

lts <- ts(retaildata[,"A3349499L"], frequency=12, start=c(1982,4))
head(lts)
##      Apr May Jun Jul Aug Sep
## 1982 6.0 5.4 5.2 5.6 5.7 5.8
lts <-  window(lts, start=1983)

The plot below shows clear uptrend with seasonality.

autoplot(lts)

Below plot shows there is a big increase from November to December and a drop from January to February. People tend consume for liquor toward the end of the year because of the holidays and so on.

ggseasonplot(lts)

The subseries plot also shows December mean liquor retailing is a lot higher than other any other month. This also shows mean for February is slightly lower than any other months.

ggsubseriesplot(lts)

The lag plots also show strong seasonality in the data. For example, lag 12 and lag 24 shows strong positive relationship. We know from the previous plots there is a big increase in liquor retailing in November and December.

gglagplot(lts, lags = 24)

Peaks tend to be 12 months apart because of seasonality. The “scalloped” shape is due the seasonality.

ggAcf(lts)

Q4 Excercise 2.6

Sales of one-family houses

From the plot below looks like there are mini cycles in the plot, this might be tied the economic cycles. Seasonal plot shows that from January to march home sales are increasing and slows down after that. Subseries plot shows mean sales for March, April and May higher than any other month. This plot also shows mean sales peak around these months and slows down after that.

autoplot(hsales)

ggseasonplot(hsales)

ggsubseriesplot(hsales)

gglagplot(hsales)

ggAcf(hsales)

Accidental deaths in USA

Plots shows that there is a clear seasonal pattern. The deaths are lowest in February each year, then rises to the peak in July, then decreases.

autoplot(usdeaths)

ggseasonplot(usdeaths)

ggsubseriesplot(usdeaths)

gglagplot(usdeaths)

ggAcf(usdeaths)

Quarterly clay brick production

This contains time series data for Australian quarterly clay brick production from 1956 to 1994. There is a clear positive uptrend from 60’s to 80’s followed by a sudden drop. The seasonal plot shows a pattern that peaks on the 3rd quarter.

autoplot(bricksq)

ggseasonplot(bricksq)

ggsubseriesplot(bricksq)

gglagplot(bricksq)

ggAcf(bricksq)

Annual average sunspot area (1875-2015)

For this series, seasonal plots cannot be created because the data are annual. The autopilot shows a cyclic pattern. The autocorrelation plot shows both positive and negative autocorrelations. High positive autocorrelation happens at lag 10 and 11, high negative autocorrelation happens at lag 5 and 16.

autoplot(sunspotarea)

gglagplot(sunspotarea)

ggAcf(sunspotarea)

US finished motor gasoline product supplied.

There is a clear upward trend in the years before 2008 and seems to be more cyclic afterward. This might be tied to the economy. The seasonal plot does not reveal a clear seasonal pattern. Subseries plot cannot be made because the time series is weekly. The autocorrelation plot shows strong autocorrelation and scalloped shape might be due to economic cycles.

autoplot(gasoline)

ggseasonplot(gasoline)

gglagplot(gasoline)

ggAcf(gasoline)