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)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.
autoplot(gold)autoplot(woolyrnq)autoplot(gas) #### b. What is the frequency of each series? Hint: apply the frequency() function.
frequency(gold)## [1] 1
frequency(woolyrnq)## [1] 4
frequency(gas)## [1] 12
which.max(gold)## [1] 770
tute1 <- read.csv("tute1.csv", header=TRUE)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.)
autoplot(mytimeseries, facets=TRUE)autoplot(mytimeseries)Check what happens when you don’t include facets=TRUE. Its put everything together.
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.
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?
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.
autoplot(usdeaths)ggseasonplot(usdeaths)ggsubseriesplot(usdeaths)gglagplot(usdeaths)ggAcf(usdeaths) We can see the month with the hightest death is july.
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.
autoplot(sunspotarea)gglagplot(sunspotarea)ggAcf(sunspotarea)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.