Question 1.
require(fpp2)
## Loading required package: fpp2
## Warning: package 'fpp2' was built under R version 3.5.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.2
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.5.2
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.5.2
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 3.5.2
time_series <-ts(rnorm(365*2),start =c( 2019,1),frequency=365)
autoplot(time_series)
require(timeDate)
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.5.2
ts<- timeSequence(as.Date("2019-01-01"),as.Date("2019-06-30"))
ts;
## GMT
## [1] [2019-01-01] [2019-01-02] [2019-01-03] [2019-01-04] [2019-01-05]
## [6] [2019-01-06] [2019-01-07] [2019-01-08] [2019-01-09] [2019-01-10]
## [11] [2019-01-11] [2019-01-12] [2019-01-13] [2019-01-14] [2019-01-15]
## [16] [2019-01-16] [2019-01-17] [2019-01-18] [2019-01-19] [2019-01-20]
## [21] [2019-01-21] [2019-01-22] [2019-01-23] [2019-01-24] [2019-01-25]
## [26] [2019-01-26] [2019-01-27] [2019-01-28] [2019-01-29] [2019-01-30]
## [31] [2019-01-31] [2019-02-01] [2019-02-02] [2019-02-03] [2019-02-04]
## [36] [2019-02-05] [2019-02-06] [2019-02-07] [2019-02-08] [2019-02-09]
## [41] [2019-02-10] [2019-02-11] [2019-02-12] [2019-02-13] [2019-02-14]
## [46] [2019-02-15] [2019-02-16] [2019-02-17] [2019-02-18] [2019-02-19]
## [51] [2019-02-20] [2019-02-21] [2019-02-22] [2019-02-23] [2019-02-24]
## [56] [2019-02-25] [2019-02-26] [2019-02-27] [2019-02-28] [2019-03-01]
## [61] [2019-03-02] [2019-03-03] [2019-03-04] [2019-03-05] [2019-03-06]
## [66] [2019-03-07] [2019-03-08] [2019-03-09] [2019-03-10] [2019-03-11]
## [71] [2019-03-12] [2019-03-13] [2019-03-14] [2019-03-15] [2019-03-16]
## [76] [2019-03-17] [2019-03-18] [2019-03-19] [2019-03-20] [2019-03-21]
## [81] [2019-03-22] [2019-03-23] [2019-03-24] [2019-03-25] [2019-03-26]
## [86] [2019-03-27] [2019-03-28] [2019-03-29] [2019-03-30] [2019-03-31]
## [91] [2019-04-01] [2019-04-02] [2019-04-03] [2019-04-04] [2019-04-05]
## [96] [2019-04-06] [2019-04-07] [2019-04-08] [2019-04-09] [2019-04-10]
## ...
## [ reached getRmetricsOption('max.print') | getOption('max.print') -- omitted 81 rows ]]
years.included <- unique( as.integer( format( x=ts, format="%Y" ) ) );
holidays <- holidayLONDON(years.included)
business.days <- ts[isBizday(ts, holidays)];
business.days
## GMT
## [1] [2019-01-02] [2019-01-03] [2019-01-04] [2019-01-07] [2019-01-08]
## [6] [2019-01-09] [2019-01-10] [2019-01-11] [2019-01-14] [2019-01-15]
## [11] [2019-01-16] [2019-01-17] [2019-01-18] [2019-01-21] [2019-01-22]
## [16] [2019-01-23] [2019-01-24] [2019-01-25] [2019-01-28] [2019-01-29]
## [21] [2019-01-30] [2019-01-31] [2019-02-01] [2019-02-04] [2019-02-05]
## [26] [2019-02-06] [2019-02-07] [2019-02-08] [2019-02-11] [2019-02-12]
## [31] [2019-02-13] [2019-02-14] [2019-02-15] [2019-02-18] [2019-02-19]
## [36] [2019-02-20] [2019-02-21] [2019-02-22] [2019-02-25] [2019-02-26]
## [41] [2019-02-27] [2019-02-28] [2019-03-01] [2019-03-04] [2019-03-05]
## [46] [2019-03-06] [2019-03-07] [2019-03-08] [2019-03-11] [2019-03-12]
## [51] [2019-03-13] [2019-03-14] [2019-03-15] [2019-03-18] [2019-03-19]
## [56] [2019-03-20] [2019-03-21] [2019-03-22] [2019-03-25] [2019-03-26]
## [61] [2019-03-27] [2019-03-28] [2019-03-29] [2019-04-01] [2019-04-02]
## [66] [2019-04-03] [2019-04-04] [2019-04-05] [2019-04-08] [2019-04-09]
## [71] [2019-04-10] [2019-04-11] [2019-04-12] [2019-04-15] [2019-04-16]
## [76] [2019-04-17] [2019-04-18] [2019-04-23] [2019-04-24] [2019-04-25]
## [81] [2019-04-26] [2019-04-29] [2019-04-30] [2019-05-01] [2019-05-02]
## [86] [2019-05-03] [2019-05-07] [2019-05-08] [2019-05-09] [2019-05-10]
## [91] [2019-05-13] [2019-05-14] [2019-05-15] [2019-05-16] [2019-05-17]
## [96] [2019-05-20] [2019-05-21] [2019-05-22] [2019-05-23] [2019-05-24]
## ...
## [ reached getRmetricsOption('max.print') | getOption('max.print') -- omitted 24 rows ]]
Question 2.
require(fpp2)
help(chicken)
## starting httpd help server ... done
autoplot(chicken)
require(fpp2)
frequency(chicken)
## [1] 1
which.max(chicken)
## [1] 22
help(dole)
autoplot(dole)
frequency(dole)
## [1] 12
which.max(dole)
## [1] 439
help(usdeaths)
autoplot(usdeaths)
frequency(usdeaths)
## [1] 12
which.max(usdeaths)
## [1] 7
help(gold)
autoplot(gold)
frequency(gold)
## [1] 1
which.max(gold)
## [1] 770
help(h02)
autoplot(h02)
frequency(h02)
## [1] 12
which.max(h02)
## [1] 162
library(fpp2)
help(gasoline)
autoplot(gasoline)
frequency(gasoline)
## [1] 52.17857
which.max(gasoline)
## [1] 1324
Question 3.
retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
mytimeseries <- ts(retaildata[,"A3349873A"], frequency=12, start=c(1982,4))
ownstr <- colnames(retaildata)[20]
mytimeseries <- ts(retaildata[,ownstr], frequency=12, start=c(1982,4))
autoplot(mytimeseries)
## There is a clear and increasing trend with strong seasonal pattern that increases in sales as the level of the series increases.
Question 4.
ddj<-diff(dj)
autoplot(ddj)
ggAcf(ddj)
## The changes in the Dow Jones Index looks white noise, because the autocorrelation is close to zero. In addtion, 95% of the spikes in the ACF lie within the bounds of the graph.
Question 5.
autoplot(arrivals)
## The arrivals from New Zealand and UK has clear seasonal patterns with an overall increasing trend. ## The arrivals from Janpan decrease a lot in the 2nd quarter compared to the other quarters. ## The arrivals from New Zealand are highest in 3rd quarter and lowest in 1st quarter. ## The arrivals from UK and US are low in 2nd and 3rd quarters and high in 1st and 4th quarter.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.