Libraries

library(kableExtra)
library(tidyverse)
library(ggplot2)
library(dplyr)
library(corrplot)
library(RColorBrewer)
library(GGally)
library(fpp2)

Forecasting: Principles & Practice

Section 2.10 - Exercise 1

  1. Use the help function to explore what the series gold, woolyrnq and gas represent.
help(gold)
## starting httpd help server ... done

‘gold’ Data Description

Daily morning gold prices in US dollars. 1 January 1985 - 31 March 1989.

help(woolyrnq)

‘woolyrnq’ Data Description

Quarterly production of woollen yarn in Australia: tonnes. Mar 1965 - Sep 1994.

help(gas)

‘gas’ Data Description

Australian monthly gas production: 1956-1995.

  1. Use autoplot() to plot each of these in separate plots.
autoplot(gold) + ggtitle('Daily morning gold prices in US dollars. 1 January 1985 - 31 March 1989')

autoplot(woolyrnq) + ggtitle('Quarterly production of woollen yarn in Australia: tonnes. Mar 1965 - Sep 1994')

autoplot(gas) + ggtitle('Australian monthly gas production: 1956-1995')

  1. 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?
frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12

Frequency of gold is 1.

Frequency of woolyrnq is 4.

Frequency of gas is 12.

Section 2.10 - Exercise 2

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.

  • You can read the data into R with the following script:

tute1 <- read.csv(“tute1.csv”, header=TRUE) View(tute1)

tute1 <- read.csv("https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-624/Homework1-Timeseries/Data/tute1.csv")
head(tute1, 20) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
X Sales AdBudget GDP
Mar-81 1020.2 659.2 251.8
Jun-81 889.2 589.0 290.9
Sep-81 795.0 512.5 290.8
Dec-81 1003.9 614.1 292.4
Mar-82 1057.7 647.2 279.1
Jun-82 944.4 602.0 254.0
Sep-82 778.5 530.7 295.6
Dec-82 932.5 608.4 271.7
Mar-83 996.5 637.9 259.6
Jun-83 907.7 582.4 280.5
Sep-83 735.1 506.8 287.2
Dec-83 958.1 606.7 278.0
Mar-84 1034.1 658.7 256.8
Jun-84 992.8 614.9 271.0
Sep-84 791.7 489.9 300.9
Dec-84 914.2 586.5 289.8
Mar-85 1106.5 663.0 266.8
Jun-85 985.1 591.7 273.7
Sep-85 823.9 502.2 301.3
Dec-85 1025.1 616.4 285.6
  • Convert the data to time series

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.)

mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
head(mytimeseries,20)
##          Sales AdBudget   GDP
## 1981 Q1 1020.2    659.2 251.8
## 1981 Q2  889.2    589.0 290.9
## 1981 Q3  795.0    512.5 290.8
## 1981 Q4 1003.9    614.1 292.4
## 1982 Q1 1057.7    647.2 279.1
## 1982 Q2  944.4    602.0 254.0
## 1982 Q3  778.5    530.7 295.6
## 1982 Q4  932.5    608.4 271.7
## 1983 Q1  996.5    637.9 259.6
## 1983 Q2  907.7    582.4 280.5
## 1983 Q3  735.1    506.8 287.2
## 1983 Q4  958.1    606.7 278.0
## 1984 Q1 1034.1    658.7 256.8
## 1984 Q2  992.8    614.9 271.0
## 1984 Q3  791.7    489.9 300.9
## 1984 Q4  914.2    586.5 289.8
## 1985 Q1 1106.5    663.0 266.8
## 1985 Q2  985.1    591.7 273.7
## 1985 Q3  823.9    502.2 301.3
## 1985 Q4 1025.1    616.4 285.6
#head(mytimeseries, 20) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
  • Construct time series plots of each of the three series

autoplot(mytimeseries, facets=TRUE) Check what happens when you don’t include facets=TRUE.

Including facets=TRUE

autoplot(mytimeseries, facets=TRUE)

Excluding facets=TRUE

autoplot(mytimeseries)

It is clear that excluding facets=TRUE condition makes the 3 time series metrics (Sales, AdBudget & GDP) appear as legends as opposed to a horizontal grid if the option is included.

Section 2.10 - Exercise 3

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.

retaildata <- readxl::read_excel("retail.xlsx", skip=1)

head(retaildata, 20) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Series ID A3349335T A3349627V A3349338X A3349398A A3349468W A3349336V A3349337W A3349397X A3349399C A3349874C A3349871W A3349790V A3349556W A3349791W A3349401C A3349873A A3349872X A3349709X A3349792X A3349789K A3349555V A3349565X A3349414R A3349799R A3349642T A3349413L A3349564W A3349416V A3349643V A3349483V A3349722T A3349727C A3349641R A3349639C A3349415T A3349349F A3349563V A3349350R A3349640L A3349566A A3349417W A3349352V A3349882C A3349561R A3349883F A3349721R A3349478A A3349637X A3349479C A3349797K A3349477X A3349719C A3349884J A3349562T A3349348C A3349480L A3349476W A3349881A A3349410F A3349481R A3349718A A3349411J A3349638A A3349654A A3349499L A3349902A A3349432V A3349656F A3349361W A3349501L A3349503T A3349360V A3349903C A3349905J A3349658K A3349575C A3349428C A3349500K A3349577J A3349433W A3349576F A3349574A A3349816F A3349815C A3349744F A3349823C A3349508C A3349742A A3349661X A3349660W A3349909T A3349824F A3349507A A3349580W A3349825J A3349434X A3349822A A3349821X A3349581X A3349908R A3349743C A3349910A A3349435A A3349365F A3349746K A3349370X A3349754K A3349670A A3349764R A3349916R A3349589T A3349590A A3349765T A3349371A A3349588R A3349763L A3349372C A3349442X A3349591C A3349671C A3349669T A3349521W A3349443A A3349835L A3349520V A3349841J A3349925T A3349450X A3349679W A3349527K A3349526J A3349598V A3349766V A3349600V A3349680F A3349378T A3349767W A3349451A A3349924R A3349843L A3349844R A3349376L A3349599W A3349377R A3349779F A3349379V A3349842K A3349532C A3349931L A3349605F A3349688X A3349456L A3349774V A3349848X A3349457R A3349851L A3349604C A3349608L A3349609R A3349773T A3349852R A3349775W A3349776X A3349607K A3349849A A3349850K A3349606J A3349932R A3349862V A3349462J A3349463K A3349334R A3349863W A3349781T A3349861T A3349626T A3349617R A3349546T A3349787F A3349333L A3349860R A3349464L A3349389X A3349461F A3349788J A3349547V A3349388W A3349870V A3349396W
1982-04-01 303.1 41.7 63.9 408.7 65.8 91.8 53.6 211.3 94.0 32.7 126.7 178.3 50.4 22.2 43.0 62.4 178.0 61.8 85.4 147.2 1250.2 257.9 17.3 34.9 310.2 58.2 55.8 59.1 173.1 93.6 26.3 119.9 104.2 42.2 15.6 31.6 34.4 123.7 36.4 48.7 85.1 916.2 139.3 NA NA 161.8 31.8 46.6 13.3 91.6 28.9 13.9 42.8 67.5 18.4 11.1 22.0 25.8 77.3 18.7 26.7 45.4 486.3 83.5 6.0 11.3 100.8 15.2 16.0 8.6 39.7 19.1 6.6 25.7 48.9 8.1 6.1 7.2 12.9 34.2 14.3 15.8 30.1 279.4 96.6 12.3 13.1 122.0 19.2 22.5 8.6 50.4 21.4 7.4 28.8 36.5 9.7 6.5 14.6 11.3 42.1 8.0 10.4 18.4 298.3 26.0 NA NA 28.4 6.1 5.1 2.4 13.6 6.7 1.9 8.7 NA 2.9 1.8 4.0 NA NA 1.9 3.5 5.4 79.9 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.7 1.2 1.6 15.5 2.7 4.4 2.6 9.7 3.7 2.2 5.9 10.3 2.3 1.1 2.5 2.2 8.1 4.4 3.2 7.6 57.1 933.4 79.6 149.6 1162.6 200.3 243.4 148.6 592.3 268.5 91.4 359.9 460.1 135.1 64.9 125.6 153.5 479.1 146.3 196.1 342.4 3396.4
1982-05-01 297.8 43.1 64.0 404.9 65.8 102.6 55.4 223.8 105.7 35.6 141.3 202.8 49.9 23.1 45.3 63.1 181.5 60.8 84.8 145.6 1300.0 257.4 18.1 34.6 310.1 62.0 58.4 59.2 179.5 95.3 27.1 122.5 110.2 42.1 15.8 31.5 34.4 123.9 36.2 48.9 85.1 931.2 136.0 NA NA 158.7 32.8 49.6 12.7 95.0 30.6 14.7 45.3 69.7 17.7 11.7 21.9 25.9 77.2 19.5 27.3 46.8 492.8 80.6 5.4 11.1 97.1 17.2 19.0 9.5 45.7 21.6 7.0 28.6 52.2 7.5 6.5 7.5 13.0 34.4 14.2 15.8 30.0 288.0 96.4 11.8 13.4 121.6 21.9 27.8 8.2 57.9 24.1 8.0 32.1 43.7 11.0 7.2 15.2 11.6 45.0 8.0 10.3 18.3 318.5 25.4 NA NA 27.7 6.3 4.7 2.5 13.4 7.4 1.9 9.3 NA 2.9 1.9 4.0 NA NA 2.0 3.5 5.5 78.9 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.1 1.4 1.6 15.1 3.0 4.9 3.3 11.1 3.8 2.1 5.9 10.6 2.5 1.0 2.5 2.0 8.0 3.4 3.3 6.7 57.3 920.5 80.8 149.7 1150.9 210.3 268.3 151.0 629.6 289.8 96.8 386.6 502.6 134.9 67.7 128.7 154.8 486.1 145.5 196.6 342.1 3497.9
1982-06-01 298.0 40.3 62.7 401.0 62.3 105.0 48.4 215.7 95.1 32.5 127.6 176.3 48.0 22.8 43.7 59.6 174.1 58.7 80.7 139.4 1234.2 261.2 18.1 34.6 313.9 53.8 53.7 59.8 167.3 85.2 24.3 109.6 96.7 38.5 15.2 29.6 33.5 116.8 35.7 47.1 82.8 887.0 143.5 NA NA 166.6 34.9 51.4 12.9 99.2 30.5 14.5 45.1 60.7 17.7 11.5 22.7 25.9 77.7 18.6 26.2 44.8 494.1 82.3 5.2 11.2 98.7 17.4 18.1 8.4 43.9 18.3 6.0 24.3 48.9 6.7 6.1 7.5 12.5 32.7 13.4 15.3 28.7 277.2 95.6 11.3 13.5 120.4 19.9 26.7 7.9 54.4 21.4 7.0 28.5 38.0 10.7 6.6 14.5 10.9 42.5 7.3 10.4 17.7 301.5 25.3 NA NA 27.7 6.4 5.2 2.1 13.7 6.7 1.8 8.6 NA 2.9 1.9 3.9 NA NA 2.0 3.1 5.1 77.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.5 1.3 1.7 15.5 2.5 4.8 2.7 9.9 3.2 2.0 5.1 9.9 2.3 1.0 2.5 2.0 7.8 3.6 3.5 7.1 55.3 933.6 77.3 149.0 1160.0 198.7 266.1 142.6 607.4 261.9 88.6 350.5 443.8 128.2 65.5 125.0 148.8 467.5 140.2 188.5 328.7 3357.8
1982-07-01 307.9 40.9 65.6 414.4 68.2 106.0 52.1 226.3 95.3 33.5 128.8 172.6 48.6 23.2 46.5 61.9 180.2 60.3 82.4 142.7 1265.0 266.1 18.9 35.2 320.2 57.9 56.9 59.8 174.5 91.6 25.6 117.2 104.6 38.9 15.2 35.2 33.4 122.7 34.6 47.5 82.1 921.3 150.2 NA NA 172.9 34.6 50.9 13.9 99.4 27.9 15.2 43.1 67.9 18.4 13.1 24.3 28.7 84.4 22.6 25.2 47.8 515.6 88.2 5.6 12.1 105.9 18.7 20.3 10.3 49.3 18.6 6.4 25.0 48.3 7.8 6.6 7.9 13.9 36.2 14.5 17.0 31.4 296.1 103.3 12.1 13.8 129.2 19.3 28.2 8.7 56.2 21.8 7.2 29.0 42.0 9.0 7.0 14.6 11.4 42.0 7.8 10.3 18.1 316.4 27.8 NA NA 30.3 5.9 5.2 2.7 13.7 7.1 1.8 8.9 NA 3.1 1.8 4.4 NA NA 1.9 3.6 5.5 82.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.2 1.4 1.6 16.1 2.8 5.1 2.4 10.2 3.4 2.1 5.4 8.8 2.6 1.1 2.6 2.0 8.3 4.0 3.5 7.5 56.3 972.6 80.4 153.5 1206.4 208.7 273.5 150.1 632.4 267.2 92.1 359.3 459.1 129.9 68.5 136.6 156.1 491.1 146.5 192.0 338.5 3486.8
1982-08-01 299.2 42.1 62.6 403.8 66.0 96.9 54.2 217.1 82.8 29.4 112.3 169.6 51.3 21.4 44.8 60.7 178.1 56.1 80.7 136.8 1217.6 247.2 19.0 33.8 300.1 59.2 56.7 62.2 178.1 85.2 23.5 108.7 92.5 39.5 14.5 34.7 33.2 122.0 32.5 49.3 81.8 883.2 144.0 NA NA 165.9 32.9 51.6 12.8 97.3 27.4 14.1 41.5 66.5 17.8 13.0 23.6 27.7 82.1 22.6 25.6 48.2 501.4 82.3 5.7 11.7 99.7 18.6 19.6 10.6 48.9 17.1 6.0 23.1 49.4 7.9 6.3 8.3 13.7 36.1 13.6 17.5 31.1 288.4 96.6 12.0 13.3 121.9 19.6 27.4 7.9 55.0 18.7 6.6 25.3 38.5 9.1 6.8 15.3 10.9 42.1 7.6 10.1 17.7 300.5 26.6 NA NA 29.0 5.7 4.8 2.9 13.4 5.8 1.7 7.5 NA 3.1 1.8 4.2 NA NA 1.9 3.6 5.5 78.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.7 1.6 1.6 15.8 2.8 4.6 2.7 10.1 3.1 2.0 5.0 8.8 2.6 0.9 2.8 2.0 8.4 3.6 3.7 7.3 55.4 923.5 81.6 147.3 1152.5 206.2 262.7 153.7 622.6 241.5 83.7 325.2 438.4 133.0 65.2 134.7 152.8 485.7 138.8 192.7 331.5 3355.9
1982-09-01 305.4 42.0 64.4 411.8 62.3 97.5 53.6 213.4 89.4 32.2 121.6 181.4 49.6 21.8 43.9 61.2 176.5 58.1 82.1 140.2 1244.9 262.4 18.4 35.4 316.2 57.1 58.9 63.6 179.6 89.5 24.3 113.8 98.3 41.7 15.1 34.2 34.5 125.5 33.9 50.7 84.6 917.9 146.9 NA NA 169.5 33.7 49.6 14.5 97.9 29.1 15.5 44.5 73.4 18.8 13.0 21.8 29.0 82.6 23.2 26.7 49.8 517.7 84.2 5.8 12.0 102.0 18.8 19.9 11.5 50.2 18.2 6.4 24.6 48.5 7.8 6.4 7.8 14.1 36.0 13.9 17.8 31.7 293.0 101.4 12.3 13.4 127.1 19.9 27.0 8.7 55.6 19.5 7.4 26.9 40.2 10.0 7.1 15.1 11.7 43.9 8.2 10.3 18.5 312.3 27.1 NA NA 29.6 5.3 4.8 2.6 12.8 5.8 1.7 7.5 NA 3.2 1.8 4.0 NA NA 1.9 3.8 5.7 79.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.9 1.4 1.8 16.0 2.6 4.3 3.1 10.0 3.4 2.2 5.6 9.2 2.6 1.0 2.8 2.2 8.6 4.2 3.9 8.1 57.5 955.9 81.4 151.8 1189.1 200.9 263.1 157.9 622.0 256.2 90.1 346.3 465.1 135.5 66.8 130.4 157.2 489.9 144.3 197.6 341.9 3454.3
1982-10-01 318.0 46.1 66.0 430.1 66.2 99.3 58.0 223.5 83.3 31.9 115.2 173.9 51.6 21.0 45.6 62.1 180.3 53.9 87.3 141.2 1264.2 285.4 20.9 38.0 344.3 66.9 59.6 64.1 190.5 93.0 25.8 118.7 102.8 46.2 16.3 35.9 36.7 135.2 37.7 54.1 91.7 983.3 143.7 NA NA 166.2 31.7 49.1 13.1 93.8 33.4 15.2 48.6 68.3 20.2 12.0 19.3 27.0 78.5 20.8 28.1 48.8 504.2 88.9 6.6 12.7 108.2 18.7 19.7 10.8 49.3 20.7 7.4 28.1 46.1 7.6 7.4 8.4 15.0 38.4 17.2 20.6 37.8 307.9 107.0 14.2 14.1 135.4 18.0 25.5 10.2 53.6 20.8 8.3 29.1 37.4 7.7 7.5 15.0 12.6 42.8 9.3 11.0 20.3 318.7 27.0 NA NA 29.5 5.5 4.2 2.6 12.3 5.3 1.6 7.0 NA 2.9 1.8 4.2 NA NA 2.0 3.9 5.9 78.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.5 1.5 1.7 16.6 3.7 4.7 3.5 11.9 3.4 2.3 5.8 9.7 2.7 1.2 2.6 2.5 9.0 4.8 4.0 8.9 61.9 999.3 90.8 157.3 1247.4 211.9 263.3 162.6 637.8 261.3 92.9 354.2 452.7 140.6 67.7 132.0 160.6 500.9 146.6 211.9 358.4 3551.5
1982-11-01 334.4 46.5 65.3 446.2 68.9 107.8 67.2 243.9 99.3 35.0 134.3 206.6 55.8 23.5 45.3 68.3 192.9 61.2 87.4 148.7 1372.6 291.9 22.4 38.2 352.5 78.1 63.2 82.5 223.8 107.9 29.0 136.9 114.6 43.5 17.5 38.0 40.7 139.7 40.3 57.3 97.7 1065.2 152.7 NA NA 175.4 33.8 53.2 14.9 101.9 35.5 15.9 51.4 73.4 21.5 13.2 19.2 29.7 83.6 22.7 27.6 50.4 536.0 87.0 6.5 12.2 105.7 21.0 22.7 13.1 56.8 23.6 8.0 31.6 58.5 8.8 7.8 8.8 15.8 41.2 17.3 20.9 38.2 332.1 108.7 14.2 13.8 136.7 19.0 27.4 13.2 59.6 23.8 8.8 32.6 42.4 8.4 7.9 15.7 13.9 45.9 9.6 11.1 20.8 337.9 28.0 NA NA 30.6 6.0 5.3 3.2 14.5 7.1 1.9 9.0 NA 3.1 2.0 4.7 NA NA 2.0 3.9 5.9 86.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.1 1.5 1.7 17.2 3.9 5.1 4.6 13.6 3.6 2.6 6.2 11.3 3.0 1.3 3.1 2.9 10.3 5.4 4.3 9.6 68.3 1031.9 92.3 156.5 1280.7 232.2 285.9 199.0 717.2 302.4 101.5 403.9 522.9 145.7 73.6 135.7 176.1 531.1 159.3 215.4 374.7 3830.5
1982-12-01 389.6 53.8 77.9 521.3 90.8 155.5 146.3 392.6 142.9 51.7 194.6 346.6 69.9 31.4 55.0 104.0 260.3 75.7 97.2 172.9 1888.3 334.6 29.7 43.9 408.2 87.5 90.3 143.0 320.8 148.2 39.8 188.0 208.5 57.2 21.5 56.5 57.3 192.5 45.2 64.1 109.3 1427.3 172.8 NA NA 198.0 42.6 79.0 29.4 151.0 48.8 22.1 70.9 127.9 30.9 16.2 23.8 41.5 112.4 24.5 31.1 55.7 715.9 99.1 8.6 14.5 122.1 23.8 30.3 25.4 79.6 33.4 11.7 45.1 88.9 12.9 10.5 11.1 23.1 57.6 22.8 24.8 47.6 440.9 128.5 16.2 16.0 160.7 23.0 37.6 26.6 87.2 34.8 13.1 47.9 71.9 11.8 11.0 19.6 21.5 63.9 13.4 12.4 25.7 457.4 32.7 NA NA 35.7 7.7 7.9 6.0 21.7 11.1 2.6 13.8 NA 4.6 2.5 5.8 NA NA 2.4 4.3 6.7 118.6 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 16.5 1.6 1.9 20.0 4.2 8.0 7.4 19.7 4.7 3.5 8.2 18.5 4.9 1.8 3.9 4.1 14.6 6.9 4.3 11.2 92.2 1190.4 111.0 182.3 1483.7 281.2 410.7 385.0 1077.0 426.1 145.2 571.4 889.3 194.0 95.8 176.7 258.7 725.2 192.6 240.5 433.1 5179.7
1983-01-01 311.4 43.8 65.1 420.3 58.0 95.1 66.6 219.7 78.5 31.4 109.8 135.3 50.1 20.7 47.4 63.9 182.1 54.2 93.0 147.2 1214.5 270.7 22.9 36.0 329.6 58.8 55.5 64.3 178.6 81.6 25.0 106.6 81.5 43.7 15.6 34.1 35.8 129.3 36.9 57.7 94.6 920.3 146.9 NA NA 169.3 28.8 50.1 14.1 92.9 29.7 14.9 44.6 64.0 22.8 12.0 17.7 27.8 80.4 20.5 30.7 51.2 502.4 82.7 7.1 12.5 102.3 19.7 18.8 9.2 47.7 20.0 6.4 26.4 43.5 8.0 6.7 8.1 13.9 36.6 15.3 24.2 39.5 295.9 94.6 15.7 12.1 122.3 16.6 25.8 9.6 52.0 18.8 7.2 26.0 35.6 7.4 6.7 14.3 11.4 39.8 8.0 11.6 19.6 295.4 26.8 NA NA 29.3 4.7 4.7 2.6 12.0 5.3 1.5 6.8 NA 2.9 1.7 3.9 NA NA 1.9 3.6 5.5 75.2 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.0 1.0 1.6 14.6 3.0 4.3 3.3 10.6 2.7 1.9 4.6 7.4 2.5 1.0 2.5 2.1 8.1 3.8 3.9 7.7 53.0 959.3 91.7 151.9 1202.8 190.7 255.4 169.9 615.9 237.7 88.8 326.5 379.2 138.6 64.9 128.5 159.3 491.4 141.8 226.9 368.6 3384.5
1983-02-01 327.2 39.3 62.3 428.8 63.7 105.1 59.2 228.0 72.9 29.4 102.3 144.2 64.7 22.1 44.0 64.8 195.5 56.7 85.1 141.8 1240.6 278.4 20.8 35.4 334.6 59.7 60.2 64.6 184.5 73.5 23.4 96.9 86.6 44.3 16.3 34.0 36.4 130.9 38.0 50.2 88.2 921.7 149.3 NA NA 170.5 26.2 47.5 12.3 86.0 25.2 12.6 37.9 53.5 20.2 11.5 17.0 25.8 74.5 19.7 27.9 47.6 470.0 85.3 6.4 11.7 103.5 18.9 19.8 8.5 47.2 17.3 5.9 23.2 39.7 8.9 6.4 7.1 13.0 35.4 13.9 21.2 35.1 284.1 100.6 13.3 12.3 126.2 16.7 24.9 9.6 51.1 18.0 7.0 25.0 33.2 7.4 6.6 13.2 11.2 38.4 7.9 10.7 18.6 292.6 26.9 NA NA 29.3 5.0 4.5 2.4 11.9 5.6 1.7 7.3 NA 3.2 1.9 3.8 NA NA 2.0 3.3 5.3 76.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.8 1.1 1.6 15.5 3.3 4.4 2.6 10.3 2.7 1.9 4.6 8.0 3.0 1.0 2.5 2.1 8.6 4.2 3.9 8.2 55.1 995.5 82.0 146.7 1224.2 194.8 267.5 159.4 621.7 216.4 82.3 298.7 378.0 152.8 66.4 122.1 157.9 499.1 143.7 204.4 348.1 3369.8
1983-03-01 350.9 43.4 65.7 460.0 66.0 124.1 67.3 257.5 93.3 34.2 127.5 180.5 63.1 24.9 47.7 70.0 205.7 60.9 83.7 144.6 1375.7 303.8 23.5 39.1 366.4 71.6 67.6 73.9 213.0 100.6 28.2 128.8 108.0 48.3 16.8 36.7 39.1 140.9 37.0 55.0 92.0 1049.2 162.4 NA NA 185.8 30.1 58.6 16.6 105.3 31.1 15.2 46.3 64.4 20.9 13.3 18.9 30.4 83.4 21.8 28.8 50.5 535.7 95.9 6.9 14.0 116.8 22.9 24.1 9.9 56.8 23.5 7.6 31.2 54.4 9.8 7.7 7.8 15.3 40.5 16.2 24.6 40.8 340.5 107.6 15.4 13.7 136.7 18.0 28.2 10.1 56.3 19.7 7.5 27.2 37.6 7.3 7.3 14.8 12.2 41.6 8.7 11.6 20.3 319.6 29.8 NA NA 32.6 6.0 5.7 3.0 14.7 6.5 1.9 8.5 NA 3.5 2.1 4.2 NA NA 2.3 3.4 5.7 89.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.8 1.1 1.8 16.7 3.6 5.3 3.1 12.0 3.8 2.5 6.3 10.6 3.1 1.1 2.6 2.2 9.1 4.0 4.4 8.5 63.1 1080.8 91.4 160.3 1332.4 219.8 315.1 184.2 719.1 279.7 97.5 377.2 472.1 157.3 73.7 133.2 174.4 538.7 151.9 213.9 365.8 3805.3
1983-04-01 323.4 43.7 61.9 429.0 58.3 112.3 57.7 228.2 111.2 39.4 150.6 199.4 51.1 24.5 52.9 65.3 193.7 63.5 79.7 143.2 1344.2 301.9 21.7 35.6 359.2 56.2 62.9 61.5 180.7 105.6 28.6 134.1 115.3 37.0 16.0 33.6 33.8 120.5 35.1 50.2 85.2 994.9 156.8 NA NA 177.8 29.3 51.3 11.1 91.7 33.1 14.8 47.8 69.3 18.3 12.5 17.4 25.9 74.1 21.3 27.0 48.3 509.0 91.0 6.2 12.9 110.1 23.0 20.7 9.3 53.0 23.3 8.2 31.5 53.0 10.5 7.5 7.3 14.8 40.1 16.7 21.6 38.3 326.0 105.2 12.4 12.8 130.3 16.4 26.3 10.1 52.9 22.2 8.2 30.4 39.7 7.4 7.3 13.7 12.1 40.5 8.8 10.4 19.2 313.0 28.0 NA NA 30.6 5.6 5.4 2.5 13.5 6.9 2.0 8.9 NA 3.1 2.1 3.9 NA NA 2.4 3.1 5.5 83.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.3 1.3 1.7 17.2 3.4 4.0 3.1 10.6 4.7 2.7 7.4 11.7 2.6 1.1 2.2 2.3 8.2 4.4 3.7 8.2 63.3 1036.4 86.4 148.1 1270.9 193.5 284.2 155.7 633.4 308.3 104.2 412.5 503.4 131.2 71.5 131.8 159.3 493.8 153.0 198.1 351.1 3665.1
1983-05-01 316.6 42.3 63.7 422.6 67.8 120.5 64.9 253.2 112.5 41.4 153.9 200.5 54.8 25.4 55.0 68.9 204.1 64.5 81.1 145.6 1379.9 281.5 21.4 36.4 339.2 62.0 67.0 65.2 194.2 101.9 28.4 130.3 112.1 40.1 16.1 36.6 35.0 127.8 34.1 52.7 86.8 990.4 159.8 NA NA 181.3 35.1 53.6 12.0 100.7 33.9 15.6 49.5 69.3 20.2 12.7 18.0 26.9 77.8 21.3 27.5 48.9 527.5 91.6 6.1 13.1 110.8 26.8 22.5 10.5 59.8 24.5 8.1 32.6 56.0 11.4 7.7 8.1 15.3 42.4 16.3 23.2 39.5 341.1 106.9 12.7 13.2 132.8 19.6 29.4 11.1 60.2 25.0 9.1 34.0 46.0 8.3 7.8 14.2 12.9 43.2 9.1 11.4 20.5 336.8 27.5 NA NA 30.2 6.2 5.6 3.0 14.7 7.0 1.9 8.9 NA 3.1 2.1 3.9 NA NA 2.2 3.6 5.8 85.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.1 1.4 1.8 17.3 3.7 4.8 3.1 11.6 4.6 2.8 7.3 11.5 2.8 1.1 2.3 2.3 8.5 4.3 5.0 9.3 65.6 1014.2 85.0 152.4 1251.7 222.9 304.9 170.1 697.9 310.8 107.7 418.5 510.6 142.0 73.5 138.9 166.5 520.8 153.2 207.4 360.5 3760.0
1983-06-01 325.4 40.4 64.9 430.6 64.2 115.0 58.6 237.8 103.6 37.1 140.7 175.2 52.3 24.6 56.2 65.7 198.8 63.0 79.7 142.8 1325.8 290.6 20.8 34.2 345.6 57.0 66.2 60.2 183.3 90.3 25.6 115.9 100.1 38.2 16.1 35.9 33.7 123.8 34.9 46.4 81.3 950.0 158.8 NA NA 180.2 30.9 53.6 12.0 96.5 34.0 15.5 49.5 72.6 19.8 12.6 18.7 26.8 77.9 21.0 26.5 47.5 524.2 94.0 6.2 13.1 113.2 28.5 22.9 9.8 61.2 22.4 7.4 29.8 51.9 11.3 7.4 7.7 14.9 41.3 15.7 21.9 37.6 335.0 106.9 13.7 13.4 134.0 18.4 25.8 11.0 55.2 22.2 8.1 30.3 37.8 7.2 7.2 14.1 12.2 40.6 8.6 10.4 19.0 316.9 27.3 NA NA 30.2 6.4 5.2 2.5 14.1 6.7 1.9 8.6 NA 2.9 2.0 4.2 NA NA 2.2 3.5 5.7 83.0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.2 1.4 2.0 17.6 3.4 4.3 2.6 10.3 3.9 2.3 6.2 10.1 2.8 1.0 2.2 2.1 8.2 4.3 5.6 9.9 62.3 1033.9 83.7 151.6 1269.3 210.5 294.4 157.0 661.8 284.6 98.3 383.0 462.4 136.0 71.3 139.7 160.3 507.3 150.7 196.4 347.1 3630.8
1983-07-01 323.1 41.6 69.5 434.2 60.8 111.7 58.8 231.3 97.4 34.1 131.5 181.4 57.7 23.9 54.6 66.9 203.0 61.9 84.7 146.6 1328.1 297.6 21.3 36.2 355.2 54.9 64.0 59.9 178.8 95.1 26.6 121.7 103.4 39.0 16.2 36.9 34.2 126.4 35.8 49.8 85.6 971.0 162.9 NA NA 185.1 32.9 55.0 14.4 102.2 33.5 16.0 49.5 65.9 20.8 13.0 19.5 29.0 82.2 22.1 27.8 49.9 534.8 98.3 6.2 13.5 118.0 25.7 22.2 11.1 58.9 24.0 7.9 31.9 51.7 8.3 8.1 8.3 15.8 40.5 18.2 23.1 41.3 342.3 106.2 13.9 13.1 133.2 18.4 30.2 9.7 58.3 24.7 8.4 33.0 40.3 7.6 7.7 14.3 12.3 41.8 8.9 10.9 19.8 326.5 28.3 NA NA 31.3 5.9 5.1 2.7 13.7 6.0 1.8 7.8 NA 2.9 2.0 4.0 NA NA 2.2 4.4 6.7 83.9 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.6 1.5 2.1 17.2 3.8 4.2 2.8 10.8 4.0 2.5 6.5 10.4 3.0 1.1 2.3 2.3 8.7 4.6 6.3 10.8 64.5 1047.4 85.9 159.5 1292.8 203.9 293.4 159.6 656.9 286.2 97.7 384.0 468.3 141.0 72.5 140.9 165.6 519.9 154.7 209.8 364.5 3686.5
1983-08-01 338.1 42.2 67.9 448.2 64.8 117.2 64.8 246.9 96.3 34.0 130.2 179.7 61.5 25.0 54.6 70.4 211.5 64.7 85.2 149.9 1366.3 309.6 22.6 37.1 369.3 58.8 72.4 65.2 196.4 91.3 25.7 117.0 101.4 47.1 17.2 39.3 37.3 140.9 37.1 53.3 90.5 1015.5 167.3 NA NA 189.4 35.1 61.0 14.0 110.1 36.6 16.4 52.9 60.4 21.2 13.9 22.1 29.5 86.7 22.8 28.7 51.5 551.0 101.7 6.7 13.8 122.1 27.8 24.9 11.2 63.9 23.0 7.9 30.9 54.0 9.0 8.5 8.5 16.3 42.3 18.6 24.6 43.2 356.4 111.9 14.2 13.5 139.6 19.4 34.2 11.0 64.6 24.1 8.4 32.4 38.0 8.9 8.2 15.3 13.1 45.5 9.2 11.7 20.8 340.9 29.6 NA NA 32.6 6.4 5.8 3.1 15.3 6.5 1.9 8.3 NA 2.9 2.2 4.0 NA NA 2.5 4.7 7.1 88.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.8 1.5 1.8 17.1 3.8 4.1 2.8 10.7 3.6 2.4 6.0 10.0 3.2 1.1 2.5 2.4 9.2 4.9 4.5 9.4 62.5 1089.4 88.5 159.1 1337.0 217.7 320.9 172.4 711.0 283.0 96.9 379.9 458.2 155.8 76.5 147.3 174.6 554.2 160.8 215.2 376.0 3816.3
1983-09-01 330.6 42.5 67.5 440.6 65.1 106.9 68.7 240.7 105.6 37.2 142.9 185.0 61.0 24.5 53.8 71.6 210.9 66.3 84.3 150.6 1370.8 310.2 22.4 37.4 370.0 57.4 69.7 66.4 193.6 94.7 26.5 121.3 105.2 46.1 16.9 38.3 37.2 138.5 36.8 54.0 90.8 1019.2 163.9 NA NA 185.1 34.6 55.0 15.1 104.7 37.0 17.5 54.5 73.9 20.5 13.4 21.5 29.6 85.1 22.8 27.7 50.5 553.9 99.1 7.0 13.4 119.5 25.8 22.8 12.3 61.0 24.4 8.2 32.6 52.3 9.1 8.3 8.2 16.4 42.0 18.4 23.8 42.3 349.7 111.3 14.8 13.2 139.3 19.6 30.1 12.1 61.9 25.6 9.2 34.8 40.3 7.6 8.2 15.2 13.6 44.5 9.8 11.7 21.5 342.3 29.2 NA NA 32.1 6.4 5.3 3.2 14.9 6.0 1.9 7.9 NA 2.9 2.0 4.2 NA NA 2.3 5.0 7.4 88.0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.5 1.5 2.1 17.1 3.8 4.0 3.1 10.9 3.6 2.5 6.1 10.3 3.2 1.0 2.3 2.4 8.9 4.5 6.4 10.9 64.1 1075.6 89.6 157.7 1322.8 213.9 295.1 181.4 690.3 298.5 103.5 402.0 482.7 152.4 74.9 144.6 176.0 547.9 162.0 215.6 377.6 3823.4
1983-10-01 351.1 45.0 66.0 462.1 66.3 114.4 84.1 264.8 97.9 37.3 135.2 194.4 56.9 24.6 55.6 74.9 212.0 63.7 80.1 143.8 1412.3 314.5 22.9 37.0 374.4 59.9 73.5 71.3 204.8 102.9 29.1 132.0 106.4 46.9 18.2 38.4 39.1 142.7 39.6 53.1 92.7 1053.0 167.2 NA NA 189.6 36.4 52.6 14.7 103.7 33.1 16.2 49.3 65.5 21.1 13.2 20.9 29.5 84.7 22.9 29.4 52.4 545.1 96.7 7.2 12.7 116.6 21.9 22.7 10.2 54.8 22.5 7.6 30.0 51.5 8.4 8.0 8.7 15.2 40.3 17.8 21.6 39.4 332.8 112.3 15.1 13.0 140.4 17.8 26.8 12.8 57.4 24.2 9.1 33.3 41.5 8.5 7.9 15.9 13.9 46.2 10.1 11.6 21.7 340.5 29.9 NA NA 33.0 6.3 4.9 3.3 14.5 6.4 1.9 8.4 NA 3.2 2.1 4.0 NA NA 2.5 5.1 7.5 88.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 16.6 1.5 2.4 20.5 3.4 5.0 3.3 11.7 3.4 2.5 5.9 11.2 3.1 1.3 2.3 2.7 9.4 5.5 7.2 12.8 71.4 1105.9 93.1 156.4 1355.4 213.3 301.1 200.2 714.6 291.8 104.0 395.8 485.3 149.9 75.8 146.9 180.8 553.5 163.1 211.0 374.1 3878.7
1983-11-01 361.5 45.8 67.2 474.5 72.8 136.5 101.2 310.4 110.2 41.0 151.2 224.9 59.3 27.8 57.7 83.4 228.2 69.4 82.9 152.3 1541.6 336.8 24.0 38.4 399.1 64.3 80.3 82.8 227.4 109.7 30.0 139.6 123.1 48.9 19.4 40.7 42.6 151.7 42.0 53.9 95.8 1136.8 175.6 NA NA 198.2 37.2 61.7 16.7 115.6 37.6 17.5 55.1 77.6 23.3 14.6 22.1 32.3 92.2 24.6 29.9 54.5 593.3 101.2 7.6 12.8 121.6 24.2 27.0 11.8 63.0 24.6 7.9 32.5 64.3 9.2 8.6 8.6 16.1 42.5 18.2 21.8 40.1 363.9 115.0 15.4 13.2 143.7 18.8 31.4 15.5 65.7 26.0 9.7 35.7 47.9 9.2 8.8 16.4 15.5 49.8 10.8 11.7 22.5 365.3 31.5 NA NA 34.7 7.2 6.2 3.4 16.8 7.0 2.1 9.1 NA 3.4 2.3 4.0 NA NA 2.8 5.2 8.0 97.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 17.3 1.5 2.4 21.1 4.0 5.5 3.6 13.1 3.7 2.8 6.5 12.6 3.3 1.5 2.8 3.2 10.8 6.7 7.1 13.8 78.0 1155.9 95.4 159.6 1410.9 230.1 350.1 235.3 815.5 320.3 111.4 431.7 568.7 158.3 83.7 153.3 198.8 594.1 175.3 215.3 390.6 4211.5

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))

myts <- ts(retaildata[,"A3349337W"],frequency=12, start=c(1982,4))

myts
##        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov
## 1982                    53.6  55.4  48.4  52.1  54.2  53.6  58.0  67.2
## 1983  66.6  59.2  67.3  57.7  64.9  58.6  58.8  64.8  68.7  84.1 101.2
## 1984  73.7  69.6  77.7  68.5  70.0  60.5  60.2  70.0  69.5  81.5  96.5
## 1985  69.4  69.8  74.1  71.9  83.6  68.8  71.8  79.4  76.0  97.0 126.8
## 1986  90.3  89.8  89.6  91.9  96.0  89.3  79.4  89.1  88.1 116.8 128.6
## 1987 103.9  97.3  97.9  97.2 106.5  88.2  97.7 100.2 110.8 137.3 150.5
## 1988 126.6 119.4 123.6 108.8 121.0 113.9 110.9 124.3 118.5 143.9 172.1
## 1989 160.7 155.2 161.0 149.3 165.6 140.1 128.2 140.4 130.2 143.3 185.3
## 1990  96.4  95.0 103.8  97.1 104.6 100.7  98.2 106.6  96.7 113.3 126.2
## 1991  89.1  99.6 129.0 125.6 127.3 111.7 114.1 118.0 119.6 121.5 128.5
## 1992 100.1 108.2 113.2 108.0  98.2  95.2 101.4  93.5 112.0 118.9 125.7
## 1993 100.7 102.8 113.5  99.2  95.4  89.3  84.4  91.1 102.2 101.4 108.5
## 1994 111.0 121.4 125.6 116.2 125.1 119.1 117.5 123.8 134.5 141.0 145.2
## 1995 120.8 121.0 132.6 116.3 113.2 120.2 124.3 134.0 140.6 163.7 176.2
## 1996 157.5 147.7 158.1 152.4 171.0 158.0 174.0 157.5 167.0 181.0 189.6
## 1997 168.0 154.9 169.9 159.8 172.7 154.1 144.9 141.3 164.3 162.7 172.8
## 1998 157.0 145.0 158.6 145.9 146.8 140.2 135.8 141.7 158.7 148.4 148.0
## 1999 133.1 120.5 132.2 126.0 141.0 135.0 143.7 144.4 171.7 185.5 167.9
## 2000 169.7 163.2 167.6 148.7 161.4 188.5 158.3 174.5 193.2 194.5 209.7
## 2001 209.6 185.2 202.2 200.0 200.3 200.3 193.6 211.4 218.2 236.3 230.6
## 2002 219.9 196.6 218.7 216.8 205.5 198.2 233.9 246.2 259.8 277.3 294.3
## 2003 247.0 229.3 250.3 241.6 247.0 258.7 271.3 291.1 312.7 324.6 315.2
## 2004 258.9 246.5 260.9 249.0 256.5 257.4 275.4 269.8 279.8 307.3 323.9
## 2005 281.8 250.6 274.1 270.3 268.2 264.0 266.9 298.6 303.1 329.4 345.6
## 2006 288.0 277.3 302.8 288.5 290.4 275.4 262.4 272.9 279.7 299.3 313.3
## 2007 286.4 268.4 286.6 260.0 273.0 248.5 259.7 272.2 293.6 294.9 294.3
## 2008 263.0 246.2 255.2 240.2 239.6 226.9 238.7 253.1 271.3 283.1 299.0
## 2009 289.3 249.6 272.1 272.9 279.4 267.8 273.1 307.7 318.2 334.0 325.0
## 2010 309.2 272.6 311.1 298.2 313.1 305.8 307.3 330.9 362.8 361.7 364.2
## 2011 311.6 283.7 322.2 310.8 319.5 305.1 308.9 355.6 384.9 401.1 382.1
## 2012 334.0 292.1 309.6 305.8 325.0 314.2 327.2 363.7 406.9 397.1 379.6
## 2013 340.0 293.9 330.7 290.7 291.8 281.1 309.8 344.6 360.7 384.7 367.9
##        Dec
## 1982 146.3
## 1983 192.3
## 1984 179.4
## 1985 221.2
## 1986 235.4
## 1987 248.8
## 1988 307.4
## 1989 228.9
## 1990 159.5
## 1991 151.4
## 1992 154.7
## 1993 179.0
## 1994 180.7
## 1995 225.4
## 1996 249.8
## 1997 248.7
## 1998 183.0
## 1999 200.7
## 2000 266.3
## 2001 291.0
## 2002 341.9
## 2003 360.8
## 2004 361.1
## 2005 395.2
## 2006 341.6
## 2007 339.3
## 2008 360.2
## 2009 348.9
## 2010 395.4
## 2011 409.0
## 2012 428.0
## 2013 430.7

Explore your chosen retail time series using the following functions:

autoplot(), ggseasonplot(), ggsubseriesplot(), gglagplot(), ggAcf()

Plot1: autoplot()

title <- 'Retail Sales for Category = A3349337W'
autoplot(myts) + ggtitle(title)

Plot2: ggseasonplot()

ggseasonplot(myts,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("$ Sales Turnover") +
  ggtitle("Seasonal plot: Retail Book Website Sales, Timeseries = A3349337W")

Polar View

ggseasonplot(myts,polar = TRUE) +
  ylab("$ Sales Turnover") +
  ggtitle("Seasonal plot: Retail Book Website Sales, Timeseries = A3349337W")

Plot3: ggsubseriesplot()

ggsubseriesplot(myts) +
  ylab("$ Sales Turnover") +
  ggtitle("Seasonal subseries plot: Retail Book Website Sales, Timeseries = A3349337W")

Plot4: gglagplot()

gglagplot(myts) + ggtitle(title)

Plot5: ggAcf()

ggAcf(myts) + ggtitle(title)

Can you spot any seasonality, cyclicity and trend? What do you learn about the series?

retaildata (Timeseries = “A3349337W”):: Observations

  • From the output of the autoplot(), it is clear that there is some strong seasonality withing each year along with a positive upward trend.
  • ggseasonplot() shows strong seasonal patterns with consistent high sales in Dec.
  • subseriesplot() shows a consistent pattern within each month.
  • The Lagplot() shows a strong positive linear pattern for most of the lags especially Lag12 showing strong season autocorrelation behavior.
  • From the ACF plot, slow gradual decrease in ACF as the lag increases is due to the trend, and seasonality is reflected by “scalloped” shape.

Section 2.10 - Exercise 6

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?

Timeseries1: hsales (Sales of one-family houses)

Monthly sales of new one-family houses sold in the USA since 1973.

hsales::Plot1: autoplot()

title <- 'Sales of one-family houses in USA (1973-1995)'
autoplot(hsales, xlab="Year", ylab="Monthly housing sales (millions)") + ggtitle(title)

hsales::Plot2: ggseasonplot()

hsales1 <- window(hsales, start=1973, end = 1983)

ggseasonplot(hsales1,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("Monthly housing sales (millions)") +
  ggtitle("Seasonal plot: Sales of new one-family houses, USA (1973-1983)")

hsales2 <- window(hsales, start=1984)

ggseasonplot(hsales2,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("Monthly housing sales (millions)") +
  ggtitle("Seasonal plot: Sales of new one-family houses, USA (1984-1995)")

Polar View

ggseasonplot(hsales,polar = TRUE) +
  ylab("Monthly housing sales (millions)") +
  ggtitle("Seasonal plot: Sales of new one-family houses, USA")

hsales::Plot3: ggsubseriesplot()

ggsubseriesplot(hsales) +
  ylab("Monthly housing sales (millions)") +
  ggtitle("Seasonal subseries plot: Sales of new one-family houses, USA")

hsales::Plot4: gglagplot()

gglagplot(hsales) + ggtitle(title)

hsales::Plot5: ggAcf()

ggAcf(hsales) + ggtitle(title)

hsales:: Observations

  • From the output of the autoplot(), it is clear that there is some strong seasonality withing each year in housing sales data along with a strong cyclical behavior with a period of 6-10 years. The data doesn’t show any trend behavior.
  • For better readability, I have decided to divide the seasonal plot into two different windows - 1973-1983 & 1984-1995. The consistent seasonal pattern observed in both the time windows are -
  • Begining (Jan & Feb) and end of the year (Dec), the housing sales are always low.
  • There is a consistent positive trend of sales increase towards the end of 1st quarter with Sales picking in March. Some of the years like 1977, 1978 and 1986 show a steep increase in sales in March is probably due to US Govet.’s favorable Community Re-investment, Tax Reforms Acts and policies etc. (Source - Wikipedia)
  • A consistent upward trend in house prices towards the months of August and October is also observable.
  • The Lagplot() shows a strong positive linear pattern for Lag1 and Lag2
  • From the ACF, the seasonality in the data is clearly visible from r1 to r12

Timeseries2: usdeaths (Accidental deaths in USA)

usdeaths::Plot1: autoplot()

title <- 'Monthly accidental deaths in USA (1973-1978)'
autoplot(usdeaths, xlab="Year") + ggtitle(title)

usdeaths::Plot2: ggseasonplot()

ggseasonplot(usdeaths,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("No. of Deaths") +
  ggtitle("Seasonal plot: US Accidental Deaths")

Polar View

ggseasonplot(usdeaths,polar = TRUE) +
  ylab("No. of Deaths") +
  ggtitle("Seasonal plot: US Accidental Deaths")

usdeaths::Plot3: ggsubseriesplot()

ggsubseriesplot(usdeaths) +
  ylab("No. of Deaths") +
  ggtitle("Seasonal subseries plot: US Accidental Deaths")

usdeaths::Plot4: gglagplot()

gglagplot(usdeaths) + ggtitle(title)

usdeaths::Plot5: ggAcf()

ggAcf(usdeaths) + ggtitle(title)

usadeaths:: Observations

  • From the output of the autoplot(), it is clear that there is very strong seasonality withing each year in usadeaths data set.
  • There is no clear trend observable in the accidental death for the limited years (1973-78) of data included in data set.
  • There is a very consistent seasonal pattern of June,July & August recording highest death rate. This is most likely due to increasing travel pattern during summer with more people hitting the road for vacation etc. Similar high accidental death pattern can be observerved during Christmas,New Year (Dec and Jan) which could also be due to heavy snowfall etc.
  • Feb is consistent with lowest no. of accidental deaths.
  • The Lagplot() shows a very strong autocrrelation with positive linear pattern for Lag12. Lag6 and Lag7 sow somehwat negative autocrrelation. - From the ACF, the seasonality in the data is clearly visible with r1 highers than the other lags. Peaks and troughs are consistently 12 months apart.

Timeseries3: bricksq (Australian Quarterly clay brick production)

bricksq::Plot1: autoplot()

title <- 'Australian Quarterly clay brick production (1956-1994)'
autoplot(bricksq, xlab="Year") + ggtitle(title)

bricksq::Plot2: ggseasonplot()

ggseasonplot(bricksq,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("Production Units") +
  ggtitle("Seasonal plot: Quarterly clay bricks Production")

Polar View

ggseasonplot(bricksq,polar = TRUE) +
  ylab("Production Units") +
  ggtitle("Seasonal plot: Quarterly clay bricks Production")

bricksq::Plot3: ggsubseriesplot()

ggsubseriesplot(bricksq) +
  ylab("Production Units") +
  ggtitle("Seasonal subseries plot: Quarterly clay bricks Production")

bricksq::Plot4: gglagplot()

gglagplot(bricksq) + ggtitle(title)

bricksq::Plot5: ggAcf()

ggAcf(bricksq) + ggtitle(title)

bricksq:: Observations

  • From the output of the autoplot(), it looks like there is cyclic behavior with period of 8-10 years with an upward positive trend for first 20 years.
  • ggsubseriesplot() shows a consistent pattern of change in seasonality within each quarter.
  • The Lagplot() shows a very consistent strong autocorrelation with positive linear pattern for mostly all the lags (Lag1 to Lag9).
  • From the ACF plot, slow gradual decrease in ACF as the lag increases is due to the trend, and seasonality is reflected by “scalloped” shape.

Timeseries4: sunspotarea (Annual average sunspot area (1875-2015))

Annual averages of the daily sunspot areas (in units of millionths of a hemisphere) for the full sun. Sunspots are magnetic regions that appear as dark spots on the surface of the sun. The Royal Greenwich Observatory compiled daily sunspot observations from May 1874 to 1976. Later data are from the US Air Force and the US National Oceanic and Atmospheric Administration. The data have been calibrated to be consistent across the whole history of observations.

sunspotarea::Plot1: autoplot()

title <- 'Annual average sunspot area (1875-2015)'
autoplot(sunspotarea, xlab="Year") + ggtitle(title)

sunspotarea::Plot2: ggseasonplot()

#ggseasonplot(sunspotarea,year.labels=TRUE,year.labels.left = TRUE) +
#  ylab("Units of millionths of a hemisphere") +
#  ggtitle("Seasonal plot: Annual average sunspot area (1875-2015)")

Polar View

#ggseasonplot(sunspotarea,polar = TRUE) +
#  ylab("Units of millionths of a hemisphere") +
#  ggtitle("Seasonal plot: Annual average sunspot area (1875-2015)")

sunspotarea::Plot3: ggsubseriesplot()

#ggsubseriesplot(sunspotarea) +
#  ylab("Units of millionths of a hemisphere") +
#  ggtitle("Seasonal subseries plot: Annual average sunspot area (1875-2015)")

sunspotarea::Plot4: gglagplot()

gglagplot(sunspotarea) + ggtitle(title)

sunspotarea::Plot5: ggAcf()

ggAcf(sunspotarea)  + ggtitle(title)

sunspotarea:: Observations

  • From the output of the autoplot(), a consistent cyclic behavior with period of 11-12 years is clearly visible. Also, the data doesn’t show any trend or seasonal behavior.
  • Because the data is annual, it cannot exhibit seasonality, thus the ggseasonplot() and ggsubseriesplot() functions return errors.
  • The Lagplot() doesn’t show any strong positive or negative linear autocorrelation pattern for mostly all the lags.
  • ACF plot shows consistent Peaks and troughs consistently spaced 11 years apart confirming strong cyclical pattern.

Timeseries5: gasoline (US finished motor gasoline product supplied)

Weekly data beginning 2 February 1991, ending 20 January 2017. Units are “million barrels per day”.

gasoline::Plot1: autoplot()

title <- 'US finished motor gasoline product supplied (1991-2017)'
autoplot(gasoline, xlab="Year") + ggtitle(title)

gasoline::Plot2: ggseasonplot()

ggseasonplot(gasoline,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("million barrels per day") +
  ggtitle("Seasonal plot: US finished motor gasoline product supplied")

Polar View

ggseasonplot(gasoline,polar = TRUE) +
  ylab("million barrels per day") +
  ggtitle("Seasonal plot: US finished motor gasoline product supplied")

gasoline::Plot3: ggsubseriesplot()

#(gasoline) +
#  ylab("million barrels per day") +
#  ggtitle("Seasonal subseries plot: US finished motor gasoline product supplied")

gasoline::Plot4: gglagplot()

gglagplot(gasoline) + ggtitle(title)

gasoline::Plot5: ggAcf()

ggAcf(gasoline) + ggtitle(title)

gasoline:: Observations

  • autoplot() shows a upward positive trend, and an apparently seasonal behavior. Although, the presence of cyclic behavior is not clear from this plot
  • ggseasonplot() confirms the presence of seasonal behavior in the dataset.
  • The Lagplot() for all lag periods show strong positive linear autocorrelation pattern.
  • Slow gradual decrease in the ACF plot as the lag increases is due to the trend, and seasonality is also reflected shape of the ACF plot.