Use the help function to explore what the series gold, woolyrnq and gas represent. Use autoplot() to plot each of these in separate plots. 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?
#install.packages("fpp2")
library(fpp2)
help(gold)
help(woolyrnq)
help(gas)
autoplot(gold) + ggtitle("Daily morning gold prices") + xlab("Day") + ylab("Price")## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] 306.25 299.50 303.45 296.75 304.40 298.35
## Qtr1 Qtr2 Qtr3 Qtr4
## 1965 6172 6709 6633 6660
## 1966 6786 6800
## Jan Feb Mar Apr May Jun
## 1956 1709 1646 1794 1878 2173 2321
## [1] 1
## [1] 4
## [1] 12
## [1] 770
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)
# Convert the data to time series
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
# Construct time series plots of each of the three series
autoplot(mytimeseries, facets=TRUE)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)
# Select one of the time series as follows (but replace the column name with your own chosen column):
myts <- ts(retaildata[,"A3349576F"], frequency=12, start=c(1982,4))
# Explore your chosen retail time series using the following functions:
autoplot(myts)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?
#ggseasonplot(sunspotarea)
#ggseasonplot(sunspotarea, polar=TRUE)
#ggsubseriesplot(sunspotarea)
gglagplot(sunspotarea)