## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## ── Attaching packages ─────────────────────────────────────────────────────────────── fpp2 2.4 ──
## ✓ ggplot2 3.3.2 ✓ fma 2.4
## ✓ forecast 8.13 ✓ expsmooth 2.3
##
Gold: Daily morning gold prices in US dollars. 1 January 1985 – 31 March 198.
woolyrnq: Quarterly production of woollen yarn in Australia: tonnes. Mar 1965 – Sep 1994.
gas: Australian monthly gas production: 1956–1995.
require(gridExtra)
## Loading required package: gridExtra
plot1<-autoplot(gold)
plot2<-autoplot(woolyrnq)
plot3<-autoplot(gas)
grid.arrange(plot1, plot2, plot3, nrow=3)
Answer: The frequency for gold is daily, for woollen yarn quarterly, for gas monthly.
frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12
which.max(gold)
## [1] 770
gold[770]
## [1] 593.7
Answer: Observation number 770 returns 593.7 which is the price of gold when time value equals 770.
tute1 <- read.csv("tute1.csv", header=TRUE)
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
autoplot(mytimeseries, facets=TRUE)
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
The second argument (skip=1) is required because the Excel sheet has two header rows.
myts <- ts(retaildata[,"A3349335T"],
frequency=12, start=c(1982,4))
A3349335T = Turnover ; New South Wales ; Supermarket and grocery stores ;
autoplot(), ggseasonplot(), ggsubseriesplot(), gglagplot(), ggAcf()
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? The series exhibits strong seasonality (dec & march months are good for Turnover ;New South Wales;Supermarket and grocery stores ;).
There is no obvious cyclicity. The series is upward trending.
seasonality March, April and May, cyclicity there appears to be a cycle , roughly 7.5 years ,
trend no visible trend , a mean reverting process.
What I learned even within the spring months there are material dips in sales (mid month dips)
autoplot(hsales)
ggseasonplot(hsales)
ggsubseriesplot(hsales)
gglagplot(hsales)
ggAcf(hsales)
seasonality summer months (Jun,Jul,Aug),
cyclicity no cycle ,
trend no visible trend.
What I learned I was “expecting” winter months to correlate more with the number of deaths (less daylight which affects mood)
autoplot(usdeaths)
ggseasonplot(usdeaths)
ggsubseriesplot(usdeaths)
gglagplot(usdeaths)
ggAcf(usdeaths)
seasonality Q3,
cyclicity there appears to be a cycle in the latter part of the timeseries (after 1974) ,
trend visible trend up to mid 1974.
What I learned Interesting trend within each quarter. We start with a low production of clay at the beginning of the quarter only for it to increase towards the end.
autoplot(bricksq)
ggseasonplot(bricksq)
ggsubseriesplot(bricksq)
gglagplot(bricksq)
ggAcf(bricksq)
seasonality no seasonality ,
cyclicity cycles are present, roughly every 10 years,
trend no visible trend ,
What I learned ACF shows meaningful positive autocorrel every 10 years, strong negative autocorrel every 5 years. annual data precents from detecting seasonality.
autoplot(sunspotarea)
gglagplot(sunspotarea)
ggAcf(sunspotarea)
seasonality hard to say but second half of the year looks to have higher supply of gasoline from the acf graph we can see that 52th week tend to be positively auto-correlated, cyclicity no clear cycle ,
trend upward trend to 2005 and then trending down to mind of 2012, from which point it started trending up again.
What I learned Interesting to note that gasoline supply tends to spike towards the end of the year.
autoplot(gasoline)
ggseasonplot(gasoline)
gglagplot(gasoline)
ggAcf(gasoline)