library(fpp2)
## Loading required package: ggplot2
## Loading required package: forecast
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'forecast':
##   method             from    
##   fitted.fracdiff    fracdiff
##   residuals.fracdiff fracdiff
## Loading required package: fma
## Loading required package: expsmooth
library(ggplot2)
library(forecast)
library(readxl)

2.1

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

help(gold)
help(woolyrnq)
help(gas)

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

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

autoplot(gold)

autoplot(woolyrnq)

autoplot(gas)

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

Anually
frequency(gold)
## [1] 1
Quarter
frequency(woolyrnq)
## [1] 4
montly
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

which is the price of 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)

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)

Check what happens when you don’t include facets=TRUE. Its put everything together.

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.

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.

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

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

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? we can observe that there is a trend at the of the year, meanig this is the most demadign season. the month november and december seem the most shopping month maybe because we have Black friday and christmas time.

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.

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

a-) hsales

autoplot(hsales)

ggseasonplot(hsales)

ggsubseriesplot(hsales)

gglagplot(hsales)

ggAcf(hsales)

we can observe that the most sales season are between march and april. we also notice they are some years where sales are high and then year when its goes down repeately.

b-) usdeaths

autoplot(usdeaths)

ggseasonplot(usdeaths)

ggsubseriesplot(usdeaths)

gglagplot(usdeaths)

ggAcf(usdeaths)

We can see the month with the hightest death is july.

c-) bricksq

autoplot(bricksq)

ggseasonplot(bricksq)

ggsubseriesplot(bricksq)

gglagplot(bricksq)

ggAcf(bricksq)

we see a constant increasing until about 1975 and then when down and up again.we can see that by quater it also increase from q1 to q2 a little bit to q3 and some years when down to q4 and other keep the same as q3.

d-) sunspotarea

autoplot(sunspotarea)

gglagplot(sunspotarea)

ggAcf(sunspotarea)

e-) gasoline.

autoplot(gasoline)

ggseasonplot(bricksq)

ggsubseriesplot(bricksq)

gglagplot(gasoline)

ggAcf(gasoline)

We can see a increasign trend until 2005 and then a decreased. Quartelly we can also its start an increase on q1 and then decreasing on q3.