Exercise 2.1

a. Plot each time series

autoplot(gold) + 
    labs(title = "Daily morning gold prices", 
         subtitle = "1/1985 - 3/1989",
         x = "Day", y = "Price (USD)")

autoplot(woolyrnq) + 
    labs(title = "Quarterly production of woollen yarn in Australia", 
         subtitle = "1965/Q1 - 1994/Q3", 
         x = "Quarter", y = "Tonnes")

autoplot(gas) + 
    labs(title = "Australian monthly gas production", 
         subtitle = "1956 - 1995", 
         x = "Month", y = "Units")

b. Frequency of each time series

  • gold: daily (1) with no seasonality period
  • woolyrnq: quarterly (4) with annual seasonality period
  • gas: monthly (12) with annual seasonality period
frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12

c. Outlier in the gold time series

The outlier is the price of $593.7 on day 770, which is approximately February 9, 1987.

(outlier <- which.max(gold))
## [1] 770
gold[outlier]
## [1] 593.7

Exercise 2.2

a. Read the data from disk into R

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

b. Convert the data to time series

mytimeseries <- ts(tute1[ , -1], start=1981, frequency=4)
head(mytimeseries)
##          Sales AdBudget   GDP
## 1981 Q1 1020.2    659.2 251.8
## 1981 Q2  889.2    589.0 290.9
## 1981 Q3  795.0    512.5 290.8
## 1981 Q4 1003.9    614.1 292.4
## 1982 Q1 1057.7    647.2 279.1
## 1982 Q2  944.4    602.0 254.0

c. Construct time series plots of each variable

Without facets=TRUE, the 3 time series appear in the same plot with a common vertical axis. This is problematic when the time series have different units / scales.

autoplot(mytimeseries, facets=TRUE) + 
  labs(title = "Quarterly mytimeseries data", 
       subtitle = "1981/Q1 - 2005/Q4", 
       x = "Year", y = "")

Exercise 2.3

a. Read the data from disk (Excel file) into R

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

b. Select a time series: 7th series ID

Note that the time series data is monthly starting in April 1982.

colID <- colnames(retaildata)[8]
myts <- ts(retaildata[ , colID], frequency=12, start=c(1982,4))

c. Explore the chosen time series

The time series (7th variable column in the retail dataset) relates to “Turnover - New South Wales - Hardware, building and garden supplies retailing”. From the plots below, it is evident that this monthly time series has:

  • Annual seasonality period of 12 months: turnover tends to increase in the second half of the year, with a sharp spike in Dec. and leading into Jan.; this likely relates to an increase in building and construction activity in the spring and summer months, and potentially a year-end purchasing effect.
  • Cyclical period of 7-10 years, which most likely relates to the economic cycle.
  • Overall trend of upward growth, which likely relates to long-term growth and inflation in the economy.
  • Strong autocorrelation, which is statistically significant out to 120 months.
autoplot(myts) + 
  labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing", 
       subtitle = "1982/04 - 2013/12", 
       x = "Month", y = "")

ggseasonplot(myts) + 
  labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing", 
       subtitle = "Seasonal plot")

ggsubseriesplot(myts) + 
  labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing", 
       subtitle = "Seasonal subseries plot", 
       x = "Month", y = "")

gglagplot(myts) + 
  labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing", 
       subtitle = "Lag plot")

ggAcf(myts, lag.max = 120) + 
  labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing", 
       subtitle = "Autocorrelation function plot")

Exercise 2.6

a. hsales

hsales: “monthly sales of new one-family houses houses sold in the USA since 1973”

  • Seasonality: annual 12-month period, with peak activity in the spring and summer months
  • Cyclicality: 7-10 year period corresponding to the economic cycle
  • Trend: none apparent, although we would expect long-term upward trend corresponding to population growth
  • Strong autocorrelation
myts <- hsales
autoplot(myts)

ggseasonplot(myts)

ggsubseriesplot(myts)

gglagplot(myts)

ggAcf(myts, lag.max = 120)

b. usdeaths

usdeaths: “monthly accidental deaths in the USA”

  • Seasonality: annual 12-month period, with peak deaths in summer months and trough in winter months
  • Cyclicality: none apparent
  • Trend: none apparent over this timeframe, although we would expect long-term upward trend corresponding to population growth
  • Strong autocorrelation
myts <- usdeaths
autoplot(myts)

ggseasonplot(myts)

ggsubseriesplot(myts)

gglagplot(myts)

ggAcf(myts, lag.max = 48)

c. bricksq

bricksq: “Australian quarterly clay brick production: 1956-1994”

  • Seasonality: annual 4-quarter period with peak activity in Q3
  • Cyclicality: 7-10 year period corresponding to the economic cycle
  • Trend: upward trend corresponding to long-term growth in the economy
  • Strong autocorrelation
myts <- bricksq
autoplot(myts)

ggseasonplot(myts)

ggsubseriesplot(myts)

gglagplot(myts)

ggAcf(myts, lag.max = 72)

d. sunspotarea

sunspotarea: “annual averages of the daily sunspot areas (in units of millionths of a hemisphere) for the full sun”, 1875-2015

  • Seasonality: an approximately 10-year solar period is evident, although strictly speaking, it’s not clear that the seasonal period is fixed exactly; so perhaps it could be considered a cyclical pattern
  • Cyclicality: it’s possible that there may be a solar cyclical pattern over >140 years; we would need more data to determine this; perhaps this could be considered a long-term trend
  • Trend: none apparent; need longer-term time series to determine any trends give the long-term nature of the observations
  • Strong autocorrelation
myts <- sunspotarea
autoplot(myts)

ggseasonplot(myts)
## Error in ggseasonplot(myts): Data are not seasonal
ggsubseriesplot(myts)
## Error in ggsubseriesplot(myts): Data are not seasonal
gglagplot(myts, lags = 12)

ggAcf(myts, lag.max = 72)

e. gasoline

gasoline: “US finished motor gasoline product supplied, weekly data beginning 2 February 1991, ending 20 January 2017”; units of “million barrels per day”

  • Seasonality: annual 52-week period with peaks in the summer months and troughs in the winter months
  • Cyclicality: 7-10 year period corresponding to the economic cycle
  • Trend: upward trend corresponding to long-term growth in the economy / population; however long-term trendline may have a more shallow slope recently because of alternative fuels (e.g., electric cars)
  • Strong autocorrelation
myts <- gasoline
autoplot(myts)

ggseasonplot(myts)

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

ggAcf(myts, lag.max = 520)