2.1

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

Daily morning gold prices in US dollars from 1 January 1985 to 31 March 1989.
Quarterly production of woollen yarn in Australia in tonnes from Mar 1965 to Sep 1994.
Australian monthly gas production in 1956–1995.

  1. Use autoplot() to plot each of these in separate plots.
autoplot(gold,main="Daily morning gold prices in US dollars",xlab='',ylab='USD')

autoplot(woolyrnq,main='Quarterly production of woollen yarn in Australia',xlab='',ylab='tonnes')

autoplot(gas,main='Australian monthly gas production',xlab='',ylab='')

  1. What is the frequency of each series? Hint: apply the frequency() function.
    Frequency of gold is 1.
    Frequency of woolyrnq is 4.
    Frequency of gas is 12.

  2. Use which.max() to spot the outlier in the gold series. Which observation was it?
    Max for gold is observation 770.
    Max for woolyrnq is observation 21.
    Max for gas is observation 475.

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.

  1. You can read the data into R with the following script:
tute1 <- read.csv(url("https://otexts.com/fpp2/extrafiles/tute1.csv"), header=TRUE)
View(tute1)
  1. Convert the data to time series
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 plots are displayed in the same figure sharing both axis.

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:
download.file('https://otexts.com/fpp2/extrafiles/retail.xlsx','retail.xlsx')
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[,"A3349398A"],
  frequency=12, start=c(1982,4))
  1. Explore your chosen retail time series using the following functions:
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?
Australian retail data of category A3349398A shows a strong increasing trend, with some seasonality but no evident cyclic behavior. Seasonal plots reveal that sales stay relatively flat throughout the year but there is an uptick towards the end of the year in December as well as decrease in February (especially in the more recent years) which could probably be associated with holiday shopping followed by a slowdown in demand for this specific category.

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.

hsales

autoplot(hsales)

ggseasonplot(hsales)

ggsubseriesplot(hsales)

gglagplot(hsales)

ggAcf(hsales)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
The sales data show strong seasonality within each year as well as cyclic behavior with an approximate period of 7-10 years. There is no apparent trend in the data.
Sales steadily increase from January and pick up in March followed by the decrease until the end of the year, meaning there exists a trend within each year. We can see strong positive relationship for lag 12 reflecting annual seasonality. Both trend within the year and seasonality are also evident from autocorrelation plot in which we see a slow decrease in the ACF as the lags increase (due to upward trend until march followed by a downward trend for the remainder of the year). In addition, because the data has seasonal frequency of about 12, we see larger autocorrelation values at lag 12.

usdeaths

autoplot(usdeaths)

ggseasonplot(usdeaths)

ggsubseriesplot(usdeaths)

gglagplot(usdeaths)

ggAcf(usdeaths)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
There is no apparent trend but clear seasonal patterns with most accidental deaths happening in July and least in February. Year 1973 seems to be higher than average, some additional research revealed that 1973 was the year of one of the highest death rates caused by motor vehicle accidents. The New York Times quoted the report by the Deparment of Transportation saying that the gasoline shortage related to the Arab oil embargo of 1973 and the lower speed limit of 55 miles an hour forced Americans to drive fewer miles at slower speeds, which has resulted in lower death rates in 1974.
Article 1
Article 2
The seasonality is demonstrated by both lags and autocorrelation plots with strongest correlation falling at lag 12; further, strongest negative correlation at lag 6 and 18 is due to throughs being about 6 months behind the peaks.

bricksq

autoplot(bricksq)

ggseasonplot(bricksq)

ggsubseriesplot(bricksq)

gglagplot(bricksq)

ggAcf(bricksq)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
There is a strong upward trend from 1956 to the beginning of 1980s, with some seasonality but no apparent cyclicality.
Brick production seems to peak in q3. There is autocorrelation due to both trend (decreasing values with increasing number of lags) and quarterly seasonality (spikes at lag 4, 8, 12, etc.).

sunspotarea

autoplot(sunspotarea)

gglagplot(sunspotarea)

ggAcf(sunspotarea)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
There is a strong cyclical pattern with a period of about 10 years. There is no trend or seasonality as the data are annual (hence, seasonal plots cannot be produced) but a noticable increase in variation within cycles leading up to late 1950s followed by a decrease. The cyclicality is also confirmed by ACF plot wtih highest values falling in lags 10, 20, and lowest values at lags 5, 15 due to negative correlation between throughs and peaks.
The highest annual average of daily sunspot areas was recorded in year 1957.

gasoline

autoplot(gasoline)

ggseasonplot(gasoline)

ggsubseriesplot(ts(gasoline, frequency=52))

gglagplot(gasoline)

ggAcf(gasoline)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
There is a visible upward trend that seems to reverse briefly for 2002-2012 and picks up again until latest observation, which could potentially indicate a beginning of a new cycle, however, it is not possible to determine presence of cycles from the available data. There’s also strong seasonality within each year.
Gasoline product supply appears to peak mid-year.