Data 624 HW 1

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

gold

help(gold)
head(gold)
## Time Series:
## Start = 1 
## End = 6 
## Frequency = 1 
## [1] 306.25 299.50 303.45 296.75 304.40 298.35

Daily morning gold prices in US dollars. 1 January 1985 – 31 March 1989.

woolyrnq

help(woolyrnq)
head(woolyrnq)
##      Qtr1 Qtr2 Qtr3 Qtr4
## 1965 6172 6709 6633 6660
## 1966 6786 6800

Quarterly production of woollen yarn in Australia: tonnes. Mar 1965 – Sep 1994.

gas

help(gas)
head(gas)
##       Jan  Feb  Mar  Apr  May  Jun
## 1956 1709 1646 1794 1878 2173 2321

Australian monthly gas production: 1956–1995.

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

GOLD

autoplot(gold) +
  ggtitle("Daily morning gold prices in US dollars. 1 January 1985 – 31 March 1989.")

woolyrnq

autoplot(woolyrnq) +
  ggtitle("Quarterly production of woollen yarn in Australia: tonnes. Mar 1965 – Sep 1994.")

gas

autoplot(gas) +
  ggtitle("Australian monthly gas production: 1956–1995.")

b. What is the frequency of each series? Hint: apply the frequency() function.

gold

frequency(gold)
## [1] 1

woolyrnq

frequency(woolyrnq)
## [1] 4

gas

frequency(gas)
## [1] 12

c. Use which.max() to spot the outlier in the gold series. Which observation was it?

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

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)

b. 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.)

c. Construct time series plots of each of the three series

autoplot(mytimeseries, facets=TRUE)

autoplot(mytimeseries)

Without facets=true each series is assigned a color, and it is plotted withn the same graph.

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.

a. You can read the data into R with the following script:

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

b. Select one of the time series as follows (but replace the column name with your own chosen column):

myts <- ts(retaildata[,"A3349352V"],
  frequency=12, start=c(1982,4))

c. 

autoplot()

autoplot(myts)

ggseasonplot()

ggseasonplot(myts)

ggsubseriesplot()

ggsubseriesplot(myts)

gglagplot()

gglagplot(myts)

ggAcf()

ggAcf(myts)

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

There seems to be an upward trend, and some seasonality as it is highest around December. In December around the time of Christmas retail spending is at it’s highest.

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()

autoplot(hsales)

ggseasonplot()

ggseasonplot(hsales)

ggsubseriesplot()

ggsubseriesplot(hsales)

gglagplot()

gglagplot(hsales)

ggAcf()

ggAcf(hsales)

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

There seems to be more of a cyclic because for a few years it goes up, and then it goes down for another few years.

usdeaths

autoplot()

autoplot(usdeaths)

ggseasonplot()

ggseasonplot(usdeaths)

ggsubseriesplot()

ggsubseriesplot(usdeaths)

gglagplot()

gglagplot(usdeaths)

ggAcf()

ggAcf(usdeaths)

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

There seems to be some seasonality with this as it seems to be higher during the months of summer.

bricksq

autoplot()

autoplot(bricksq)

ggseasonplot()

ggseasonplot(bricksq)

ggsubseriesplot()

ggsubseriesplot(bricksq)

gglagplot()

gglagplot(bricksq)

ggAcf()

ggAcf(bricksq)

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

There seems to be an upward trend at the beginning then it starts going down a little while still going upward.

sunspotarea

autoplot()

autoplot(sunspotarea)

gglagplot()

gglagplot(sunspotarea)

ggAcf()

ggAcf(sunspotarea)

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

There is no seasonality with this, and seems to be more cyclic.

gasoline

autoplot()

autoplot(gasoline)

ggseasonplot()

ggseasonplot(gasoline)

gglagplot()

gglagplot(gasoline)

ggAcf()

ggAcf(gasoline)

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

Here there seems to be an upward trend, sometime after 2005 it goes down, then it goes up again. A subseriesplot cannot be done with this since there is a non-integer frequency.