Exercise 2.1

Use the help function to explore what the series gold, woolyrnq and gas represent.

  1. Use autoplot() to plot each of these in separate plots.
autoplot(gold)

autoplot(woolyrnq)

autoplot(gas)

  1. What is the frequency of each series? Hint: apply the frequency() function.
frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12
  1. Use which.max() to spot the outlier in the gold series. Which observation was it?
which.max(gold)
## [1] 770

Exercise 2.2

Download the file tute1.csv from the book website, open it in Excel (or some other spreadsheet application), and review its contents. You should find four columns of information. Columns B through D each contain a quarterly series, labelled Sales, AdBudget and GDP. Sales contains the quarterly sales for a small company over the period 1981-2005. AdBudget is the advertising budget and GDP is the gross domestic product. All series have been adjusted for inflation. a. You can read the data into R with the following script:

tute1 <- read.csv("tute1.csv", header=TRUE)
View(tute1)
  1. Convert the data to time
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)

(The [,-1] removes the first column which contains the quarters as we don’t need them now.)

  1. Construct time series plots of each of the three series
autoplot(mytimeseries, facets=TRUE)

Check what happens when you don’t include facets=TRUE.

autoplot(mytimeseries)

The plot appears in color and share the same scale.

Exercise 2.3

Download some monthly Australian retail data from the book website. These represent retail sales in various categories for different Australian states, and are stored in a MS-Excel file.

  1. You can read the data into R with the following script:
retaildata <- readxl::read_excel("retail.xlsx", skip=1)

The second argument (skip=1) is required because the Excel sheet has two header rows.

  1. Select one of the time series as follows (but replace the column name with your own chosen column):
myts <- ts(retaildata[,"A3349335T"],
  frequency=12, start=c(1982,4))
  1. Explore your chosen retail time series using the following functions: autoplot(), ggseasonplot(), ggsubseriesplot(), gglagplot(), ggAcf()
autoplot(myts)

ggseasonplot(myts)

ggsubseriesplot(myts)

gglagplot(myts)

ggAcf(myts)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?

The plot has increasing trend, and strong seasonality. There are peaks towards the end of year which can suggests shopping season brought by holidays. In addition, it appears the March, May, August, and Oct have increase retail activities than other months.

Exercise 2.6

Use the following graphics functions: autoplot(), ggseasonplot(), ggsubseriesplot(), gglagplot(), ggAcf() and explore features from the following time series: hsales, usdeaths, bricksq, sunspotarea, gasoline.

Monthly sales of one-family houses

autoplot(hsales)

ggseasonplot(hsales)

ggsubseriesplot(hsales)

gglagplot(hsales)

ggAcf(hsales)

The graphs seem to exhibit a 10-year cycle. The month of March seasonally has peaks indicating more sales than any other months, The late years of 1970s seems better in selling one-family houses than the early 80s.

Monthly accidental deaths in the USA

autoplot(usdeaths)

ggseasonplot(usdeaths)

ggsubseriesplot(usdeaths)

gglagplot(usdeaths)

ggAcf(usdeaths)

The graphs seems to indicate a seasonal rise in US deaths during the middle of year; the rise and fall in numbers roughly coincides with beginning and closing of summer months. In general, the lowest number of deaths is in the month of February.

Quarterly clay brick production

autoplot(bricksq)

ggseasonplot(bricksq)

ggsubseriesplot(bricksq)

gglagplot(bricksq)

ggAcf(bricksq)

The graphs seems to exhibit upward trend with strong seasonality, and a 5-7 year cycle from mid-70s. In general, within each year, Q2 and Q3 have higher production than Q1 and Q4.

Annual average sunspot area (1875-2015)

autoplot(sunspotarea)

#ggseasonplot(sunspotarea)
#ggsubseriesplot(sunspotarea)
gglagplot(sunspotarea)

ggAcf(sunspotarea)

The graphs exhibits a 10-year cycle, reaching the peak every 10 years while the throughs are every 5 years. Since data is annually, no seasonal graphs can be created.

Weekly US finished motor gasoline product supplied

autoplot(gasoline)

ggseasonplot(gasoline)

#ggsubseriesplot(gasoline)
gglagplot(gasoline)

ggAcf(gasoline)

The series shows an upward trend which dips in mid 2000s then eventually seem to recover after few years. Since the data is weekly, the correlation of number of barrels produced seem strong between lags.