R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

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

Including Plots

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.

Number 1

library(fpp)
## Warning: package 'fpp' was built under R version 3.4.4
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.4.4
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.4.4
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 3.4.4
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 3.4.4
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.4.4
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: tseries
## Warning: package 'tseries' was built under R version 3.4.4
ts1 <- ts(rnorm(365*2), start = 2010, frequency = 365)
autoplot(ts1)

?isBizday
## starting httpd help server ...
##  done
?ts
library(timeDate)
## Warning: package 'timeDate' was built under R version 3.4.4
dates <- timeSequence(as.Date("2010-1-1"),as.Date("2010-6-30"))

business <- dates[isBizday(dates)]
business
## GMT
##   [1] [2010-01-01] [2010-01-04] [2010-01-05] [2010-01-06] [2010-01-07]
##   [6] [2010-01-08] [2010-01-11] [2010-01-12] [2010-01-13] [2010-01-14]
##  [11] [2010-01-15] [2010-01-18] [2010-01-19] [2010-01-20] [2010-01-21]
##  [16] [2010-01-22] [2010-01-25] [2010-01-26] [2010-01-27] [2010-01-28]
##  [21] [2010-01-29] [2010-02-01] [2010-02-02] [2010-02-03] [2010-02-04]
##  [26] [2010-02-05] [2010-02-08] [2010-02-09] [2010-02-10] [2010-02-11]
##  [31] [2010-02-12] [2010-02-15] [2010-02-16] [2010-02-17] [2010-02-18]
##  [36] [2010-02-19] [2010-02-22] [2010-02-23] [2010-02-24] [2010-02-25]
##  [41] [2010-02-26] [2010-03-01] [2010-03-02] [2010-03-03] [2010-03-04]
##  [46] [2010-03-05] [2010-03-08] [2010-03-09] [2010-03-10] [2010-03-11]
##  [51] [2010-03-12] [2010-03-15] [2010-03-16] [2010-03-17] [2010-03-18]
##  [56] [2010-03-19] [2010-03-22] [2010-03-23] [2010-03-24] [2010-03-25]
##  [61] [2010-03-26] [2010-03-29] [2010-03-30] [2010-03-31] [2010-04-01]
##  [66] [2010-04-02] [2010-04-05] [2010-04-06] [2010-04-07] [2010-04-08]
##  [71] [2010-04-09] [2010-04-12] [2010-04-13] [2010-04-14] [2010-04-15]
##  [76] [2010-04-16] [2010-04-19] [2010-04-20] [2010-04-21] [2010-04-22]
##  [81] [2010-04-23] [2010-04-26] [2010-04-27] [2010-04-28] [2010-04-29]
##  [86] [2010-04-30] [2010-05-03] [2010-05-04] [2010-05-05] [2010-05-06]
##  [91] [2010-05-07] [2010-05-10] [2010-05-11] [2010-05-12] [2010-05-13]
##  [96] [2010-05-14] [2010-05-17] [2010-05-18] [2010-05-19] [2010-05-20]
## ...
##  [ reached getRmetricsOption('max.print') | getOption('max.print') -- omitted 29 rows ]]
ts2 <- ts(rnorm(length(business)), start = c(2010,1), frequency = 365)
ts2
## Time Series:
## Start = c(2010, 1) 
## End = c(2010, 129) 
## Frequency = 365 
##   [1]  0.38378165 -0.20448265  0.48174765 -0.15612755 -0.52027467
##   [6]  0.20445821  2.49507456  1.36726068  0.51205815  0.92040707
##  [11]  0.19546016  0.05076400 -0.54005649  0.10241353 -1.50406510
##  [16]  1.28616219  1.94280822 -0.53813345  0.10507438 -0.43752833
##  [21]  1.03908586 -1.18364436  0.37401260 -0.62736455 -0.65499917
##  [26]  1.48831916 -1.36609322 -0.54770789  1.06473846  0.41512580
##  [31] -1.14009897 -1.91125865 -0.55396255  1.71747910  0.86061057
##  [36] -1.46536771 -0.46496409 -1.94105578 -0.53869661 -0.05070202
##  [41]  0.14745004 -0.07665206  0.30249592  0.85448473  0.06924664
##  [46] -0.38105206 -0.74486530  0.40102873 -0.63608796 -2.58193444
##  [51]  0.23907891  0.37438033 -0.14025451 -1.26811995 -1.73986399
##  [56] -0.01614162 -0.83718911  0.28358625 -0.32113235  1.45457592
##  [61] -0.38411648 -0.37940028  0.22877091  1.66704592  0.42986612
##  [66]  2.20147512  0.66491603  0.53839824  0.64659604  1.48939734
##  [71] -1.21181981 -0.23202491 -1.09397324  0.85307574 -2.12091362
##  [76] -0.12654950 -0.07284300 -0.32857246  0.70988557 -0.76012637
##  [81]  1.18712793 -0.36347610  0.87534601 -0.64591796  2.42409822
##  [86] -1.10958230 -0.30954393 -1.55373800 -0.21990234 -0.17369884
##  [91] -0.19320702  1.19373777  2.14245279 -0.59223335 -0.42118981
##  [96] -0.97067763 -0.36856753 -0.28869996  0.78298201 -0.24686290
## [101]  0.16660872 -0.98073682  0.81181856  0.79882419  1.30088998
## [106] -1.18020902  0.95906955  0.85768521 -0.27132015  0.56197395
## [111]  0.83162590  0.75028707  0.54622155 -1.18905031  0.35119738
## [116] -1.08852838  0.24036905  1.05075169 -0.03811632  0.08142541
## [121]  0.44639501 -1.28634252 -0.49368911  0.02437057 -0.70188245
## [126]  0.77816905 -0.05943031 -1.06835757  0.77056122
autoplot(ts2)

library(zoo)
ts2 <- zoo(rnorm(length(business)), order.by = business)
plot.zoo(ts2)

Number 2

library(fpp2)
## Warning: package 'fpp2' was built under R version 3.4.4
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.4.3
## 
## Attaching package: 'fpp2'
## The following objects are masked from 'package:fpp':
## 
##     ausair, ausbeer, austa, austourists, debitcards, departures,
##     elecequip, euretail, guinearice, oil, sunspotarea, usmelec
help(chicken)
autoplot(chicken)

which.max(chicken)
## [1] 22
frequency(chicken)
## [1] 1

The graph has a steady downward slop starting about 1945 and continuing through the 1990s. Before 1945, the grapg is speratic.

help(dole)
autoplot(dole)

which.max(dole)
## [1] 439
frequency(dole)
## [1] 12

The grapgh is steady from 1965 to 1975 where there is a jump of about 200,000, has a steady incline until about 1982 where it jumps again about 250,000. In about 1982, there is a steady decline for about 8 years and then it skyrockets in 1990.

help(usdeaths)
autoplot(usdeaths)

which.max(usdeaths)
## [1] 7
frequency(usdeaths)
## [1] 12

This graph has seasonality. At the begining of the year there is a low in deaths and in the middle of the year there is a high.

help(gold)
autoplot(gold)

which.max(gold)
## [1] 770
?which.max
frequency(gold)
## [1] 1

The value at 770 appears to be an outliar. This graph looks like it has cyclicity.

help(h02)
autoplot(h02)

which.max(h02)
## [1] 162
frequency(h02)
## [1] 12

The pharmaceutical products have seasonality. They reach a peak for the year at the end and then drop for a low right after the first of the year.

help(gasoline)
autoplot(gasoline)

which.max(gasoline)
## [1] 1324
frequency(gasoline)
## [1] 52.17857

This graph appears to have seasonality with lows in the winter and peaks in the summer.

Number 3 The link is not working. The site can not be reached.

Number 4

ddj <- diff(dj)
autoplot(dj)

ggAcf(dj)

Yes the changes in the Dow Jones Index look like white noise.

Number 5

autoplot(arrivals)

The US has seasonality just at a lower variance. The seasonality for New Zeland is inversaly related to Japan and UK. The variance in the seasonality in the UK grows as years pass. Japan has a upward trend until about 1992 and then they start a downward trend.