library(tidyverse)
library(fpp2)

2.1

autoplot(gold)

autoplot(woolyrnq)

autoplot(gas)

frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12
which.max(gold)
## [1] 770

2.2

tute1 <- read_csv("http://otexts.com/fpp2/extrafiles/tute1.csv")
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
autoplot(mytimeseries, facets=TRUE)

autoplot(mytimeseries)

2.3

retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
myts <- ts(retaildata[,5],  frequency=12, start=c(1982,4))
autoplot(myts)

ggseasonplot(myts)

ggsubseriesplot(myts)

gglagplot(myts)

ggAcf(myts)

This data shows linearity and seasonality. The Subseries plot shows sales generally take a dip in February, rebound in March, stay flat from April to November and has a spike in December. The season plot shows this trend has become more pronounced in the last decase. Lag plots show very high annual seasonality but all other lags trend positively. The autocorrelate plot shows light scalloping at 12 months and overall trending downwards, consistent with earlier observations.

2.6

fppsplots <- function(x) {
  list(autoplot(x), 
       ggseasonplot(x), 
       ggsubseriesplot(x), 
       gglagplot(x), 
       ggAcf(x)
  )
}

fppsplots(hsales)
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

fppsplots(usdeaths)
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

fppsplots(bricksq)
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

autoplot(sunspotarea)

#ggseasonplot(sunspotarea) not seasonal error
#ggsubseriesplot(sunspotarea) not seasonal error
gglagplot(sunspotarea)

ggAcf(sunspotarea)

autoplot(gasoline)

ggseasonplot(gasoline)

#ggsubseriesplot(gasoline) Each season requires at least 2 observations. This may be caused from specifying a time-series with non-integer frequency error
gglagplot(gasoline)

ggAcf(gasoline)

hsales: annual seasonality with cycles and no noticable trend. usdeaths: annual seasonality with no cycles or noticable trend. bricksqft: annual seasonality, positive linear correlation until a crach in 1975 which starts a cyclic pattern. sunspotarea: cycles, no seasonality, no trend, possibily a larger hundred year cycle gasoline: annual seasonaility, cycles, seems to be a positive linear correlation.