Calvin A.Cox

Data 624 - Predictive Analysis HW#1

#Libraries
#install.packages(forecast)
library(forecast)

Gold

Time series data of the daily morning gold prices in US dollars. 1 January 1985 – 31 March 1989

help(gold)
autoplot(gold)

Woolyrnq

Time series data of the quarterly production of woollen yarn in Australia: tonnes. Mar 1965 – Sep 1994.

help (woolyrnq)
autoplot(woolyrnq)

Gas

Time series data of Australian monthly gas production: 1956–1995.

help (gas)
autoplot(gas)

Frequency

Gold: 1 Woolyrnq: 4 Gas: 12

## 1.b - Frequency
frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12

Outlier

The outlier in the gold series is 770.

## 1.c Which Max
which.max(gold)
## [1] 770
## Which observation was it?

Question 2a - Downlaod file tute1.csv

## 2.a You can read the data into R with the following script:
tute1 <- read.csv('tute1.csv',header = TRUE)
#View(tute1)
head(tute1,5)
##        X  Sales AdBudget   GDP
## 1 Mar-81 1020.2    659.2 251.8
## 2 Jun-81  889.2    589.0 290.9
## 3 Sep-81  795.0    512.5 290.8
## 4 Dec-81 1003.9    614.1 292.4
## 5 Mar-82 1057.7    647.2 279.1

2b - Convert tute1 data to time series

## 2.b - Convert the data to time series
mytimeseries <- ts(tute1[,-1], start=1981, frequency = 4)

2c - Construct time series plots of each of the three series.

# 2c.  Construct time series plots of each of the three series
autoplot(mytimeseries, facets=TRUE)

2c. Construct time series plots of each of the three series with Facets = False

# 2c. Construct time series plots of each of the three series - Facets = False

autoplot(mytimeseries,facets = FALSE)

3a - Read in monthly Australian retail data.

library(readxl)
## Warning: package 'readxl' was built under R version 3.4.4
#3a.  You can read the data into R with the following script:

retaildata <- readxl::read_excel("retail.xlsx", skip=1)
## readxl works best with a newer version of the tibble package.
## You currently have tibble v1.3.4.
## Falling back to column name repair from tibble <= v1.4.2.
## Message displays once per session.
head(retaildata,5)
## # A tibble: 5 x 190
##   `Series ID` A3349335T A3349627V A3349338X A3349398A A3349468W A3349336V
##        <dttm>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>
## 1  1982-04-01     303.1      41.7      63.9     408.7      65.8      91.8
## 2  1982-05-01     297.8      43.1      64.0     404.9      65.8     102.6
## 3  1982-06-01     298.0      40.3      62.7     401.0      62.3     105.0
## 4  1982-07-01     307.9      40.9      65.6     414.4      68.2     106.0
## 5  1982-08-01     299.2      42.1      62.6     403.8      66.0      96.9
## # ... with 183 more variables: A3349337W <dbl>, A3349397X <dbl>,
## #   A3349399C <dbl>, A3349874C <dbl>, A3349871W <dbl>, A3349790V <dbl>,
## #   A3349556W <dbl>, A3349791W <dbl>, A3349401C <dbl>, A3349873A <dbl>,
## #   A3349872X <dbl>, A3349709X <dbl>, A3349792X <dbl>, A3349789K <dbl>,
## #   A3349555V <dbl>, A3349565X <dbl>, A3349414R <dbl>, A3349799R <dbl>,
## #   A3349642T <dbl>, A3349413L <dbl>, A3349564W <dbl>, A3349416V <dbl>,
## #   A3349643V <dbl>, A3349483V <dbl>, A3349722T <dbl>, A3349727C <dbl>,
## #   A3349641R <dbl>, A3349639C <dbl>, A3349415T <dbl>, A3349349F <dbl>,
## #   A3349563V <dbl>, A3349350R <dbl>, A3349640L <dbl>, A3349566A <dbl>,
## #   A3349417W <dbl>, A3349352V <dbl>, A3349882C <dbl>, A3349561R <dbl>,
## #   A3349883F <dbl>, A3349721R <dbl>, A3349478A <dbl>, A3349637X <dbl>,
## #   A3349479C <dbl>, A3349797K <dbl>, A3349477X <dbl>, A3349719C <dbl>,
## #   A3349884J <dbl>, A3349562T <dbl>, A3349348C <dbl>, A3349480L <dbl>,
## #   A3349476W <dbl>, A3349881A <dbl>, A3349410F <dbl>, A3349481R <dbl>,
## #   A3349718A <dbl>, A3349411J <dbl>, A3349638A <dbl>, A3349654A <dbl>,
## #   A3349499L <dbl>, A3349902A <dbl>, A3349432V <dbl>, A3349656F <dbl>,
## #   A3349361W <dbl>, A3349501L <dbl>, A3349503T <dbl>, A3349360V <dbl>,
## #   A3349903C <dbl>, A3349905J <dbl>, A3349658K <dbl>, A3349575C <dbl>,
## #   A3349428C <dbl>, A3349500K <dbl>, A3349577J <dbl>, A3349433W <dbl>,
## #   A3349576F <dbl>, A3349574A <dbl>, A3349816F <dbl>, A3349815C <dbl>,
## #   A3349744F <dbl>, A3349823C <dbl>, A3349508C <dbl>, A3349742A <dbl>,
## #   A3349661X <dbl>, A3349660W <dbl>, A3349909T <dbl>, A3349824F <dbl>,
## #   A3349507A <dbl>, A3349580W <dbl>, A3349825J <dbl>, A3349434X <dbl>,
## #   A3349822A <dbl>, A3349821X <dbl>, A3349581X <dbl>, A3349908R <dbl>,
## #   A3349743C <dbl>, A3349910A <dbl>, A3349435A <dbl>, A3349365F <dbl>,
## #   A3349746K <dbl>, A3349370X <dbl>, ...

3b - Choosing a time series from the retail data

#3b. Select one of the time series as follows (but replace the column name with your own chosen column):

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

3c - Explore the chosen retail time series data

Quesions:

Can you spot any seasonality, cyclicity and trend? From reviewing the seasonal and subseries plots it looks like there is a seasonality effect occuring in March, December and Possible August of each year. Based on the ACF plot, hence the downward slope of this plot indicates a positive trend in the time series.

#3c. Explore your chosen retail time series using the following functions:

autoplot(myts)

ggseasonplot(myts)

ggsubseriesplot(myts)

gglagplot(myts)

ggAcf(myts)

  1. Exploring features from hsales.

Questions:

Can you spot any seasonality, cyclicity and trend? Seasonal effects seems to occur in January -low sales followed by high sales in March. I’m also not seeing much of a trend when reviewing the ACF plot.

#6. Explore your chosen retail time series using the following functions:
library(fpp2)
## Warning: package 'fpp2' was built under R version 3.4.4
## Loading required package: ggplot2
## Loading required package: fma
## Loading required package: expsmooth
autoplot(hsales)

ggseasonplot(hsales)

ggsubseriesplot(hsales)

gglagplot(hsales)

ggAcf(hsales)

# Questions: 
#Can you spot any seasonality, cyclicity and trend?
#What do you learn about the series?
  1. Exploring features from usdeaths.

Questions:

Can you spot any seasonality, cyclicity and trend? Major seasonal activity occuring in July as seen on the seasonal and subseries plots. The ACF plot does not indicate any particular trend occuring in this series and may even show some noise in the data.

library(fpp2)

autoplot(usdeaths)

ggseasonplot(usdeaths)

ggsubseriesplot(usdeaths)

gglagplot(usdeaths)

ggAcf(usdeaths)

# Questions: 
#Can you spot any seasonality, cyclicity and trend?
#What do you learn about the series?
  1. Exploring features from bricksq.

Questions:

Can you spot any seasonality, cyclicity and trend? There doesn’t apear to be any seaonality effects in this data based on the seaonality plot. In reviewing the ACF plot the series do appear to be trending upward.

library(fpp2)

autoplot(bricksq)

ggseasonplot(bricksq)

ggsubseriesplot(bricksq)

gglagplot(bricksq)

ggAcf(bricksq)

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

Questions:

Can you spot any seasonality, cyclicity and trend? This series doesn’t appear to have much seasonality or trend. In fact an error occurred when attempting to plot the seaonal or subseries plots.

library(fpp2)

autoplot(sunspotarea)

#ggseasonplot(sunspotarea) - Error - Data are not seasonal
#ggsubseriesplot(sunspotarea) - Error - Data are not seasonal
gglagplot(sunspotarea)

ggAcf(sunspotarea)

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

Questions:

Can you spot any seasonality, cyclicity and trend? This is an interesting time series as by looking at the series itself, it doesn’t appear to show much of a trend but can clearly see a trend when reviewing the ACF plot. I’m also noticing some sort of seaonality as well.

library(fpp2)

autoplot(gasoline)

ggseasonplot(gasoline)

# ggsubseriesplot(gasoline) - Error - Each season requires at least 2 observations. This may be caused from specifying a time-series with non-integer frequency.

gglagplot(gasoline)

ggAcf(gasoline)

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