#install.packages("GGally")
library(GGally)
## Loading required package: ggplot2
library(fpp2)
## Loading required package: forecast
## Loading required package: fma
##
## Attaching package: 'fma'
## The following object is masked from 'package:GGally':
##
## pigs
## Loading required package: expsmooth
library(readxl)
Use the help function to explore what the series gold, woolyrnq and gas represent.
Use autoplot() to plot each of these in separate plots. What is the frequency of each series? Hint: apply the frequency() function. Use which.max() to spot the outlier in the gold series. Which observation was it
autoplot(gold)
autoplot(woolyrnq)
autoplot(gas)
What is the frequency of each series? Hint: apply the frequency() function.
Frequency of gold
frequency(gold)
## [1] 1
Frequency of woolyrnq
frequency(woolyrnq)
## [1] 4
Frequency of gas
frequency(gas)
## [1] 12
Use which.max() to spot the outlier in the gold series. Which observation was it?
which.max(gold)
## [1] 770
It was when the price of gold was close to 600 at time =770
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.
tute1 <- read.csv("C:/Users/Mezu/Documents/tute1.csv", header=TRUE)
#View(tute1)
Convert the data to time series
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
Construct time series plots of each of the three series
autoplot(mytimeseries, facets=TRUE)
when facets=TRUE is omitted
autoplot(mytimeseries)
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.
retaildata <- readxl::read_excel("C:/Users/Mezu/Documents/retail.xlsx", skip=1)
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)
We can see this dataset is very seasonal. We can see that in the last quarter that is a clear upward trend every year. On a yearly bases the sales seems to going up as well.
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?
hsales
autoplot(hsales)
ggseasonplot(hsales)
gglagplot(hsales)
ggAcf(hsales)
In this dataset, it looks like there is a seasonal pick sales between Feb and Mar then a lower sales for the rest of the year, we can see this clearly in the seasonal plot graph. There is no clear trend in this dataset nor any cycles
We can see from the Autocorrelation plot that the lags less than 6 confirm this seasonality in the data due to the peaks after couple of lags
usdeaths dataset
autoplot(usdeaths)
ggseasonplot(usdeaths)
gglagplot(usdeaths)
ggAcf(usdeaths)
In this dataset, it looks like there is a seasonal pick deaths from Jun peaking in July then a decreasing number of deaths for the rest of the year, we can see this clearly in the seasonal plot graph. There is also a big drop in number of deaths in Feb, Sept and Nov. There is no clear trend in this dataset nor any cycles
We can see from the Autocorrelation plot that the lags less than 6 confirm this seasonality in the data due to the peaks after couple of lags
bricksq dataset
autoplot(bricksq)
ggseasonplot(bricksq)
gglagplot(bricksq)
ggAcf(bricksq)
In this bricksq dataset it looks slightly seasonal during the Q2, there is an increase for most years, then a little more increase after that. This dataset also shows an upward trend from year to year. There is no clear cycle. From the Autocorrelation plot we see the confirmation of this upward trend and some seasonality
sunspotarea dataset
autoplot(sunspotarea)
#ggseasonplot(sunspotarea)
gglagplot(sunspotarea)
ggAcf(sunspotarea)
This dataset does not have a seasonality but I can say it has a cyclic nature to it. Basically every couple of years there are picks and droughs. I don’t see any trend in this dataset
gasoline dataset
autoplot(gasoline)
ggseasonplot(gasoline)
gglagplot(gasoline)
ggAcf(gasoline)
In this dataset it shows some a very slight seasonality according to the lag and autocorrelation plots. There is also an upward trend and a cyclic component to this time series.