Use the help function to explore what the series gold, woolyrnq and gas represent.
autoplot() to plot each of these in separate plots.autoplot(gold)
autoplot(woolyrnq)
autoplot(gas)
frequency() function.frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12
which.max() to spot the outlier in the gold series. Which observation was it?which.max(gold)
## [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. a. You can read the data into R with the following script:
tute1 <- read.csv("tute1.csv", header=TRUE)
View(tute1)
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.)
autoplot(mytimeseries, facets=TRUE)
Check what happens when you don’t include facets=TRUE.
autoplot(mytimeseries)
The plot appears in color and share the same scale.
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.
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
The second argument (skip=1) is required because the Excel sheet has two header rows.
myts <- ts(retaildata[,"A3349335T"],
frequency=12, start=c(1982,4))
autoplot(), ggseasonplot(), ggsubseriesplot(), gglagplot(), ggAcf()autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
gglagplot(myts)
ggAcf(myts)
Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
The plot has increasing trend, and strong seasonality. There are peaks towards the end of year which can suggests shopping season brought by holidays. In addition, it appears the March, May, August, and Oct have increase retail activities than other months.
Use the following graphics functions: autoplot(), ggseasonplot(), ggsubseriesplot(), gglagplot(), ggAcf() and explore features from the following time series: hsales, usdeaths, bricksq, sunspotarea, gasoline.
autoplot(hsales)
ggseasonplot(hsales)
ggsubseriesplot(hsales)
gglagplot(hsales)
ggAcf(hsales)
The graphs seem to exhibit a 10-year cycle. The month of March seasonally has peaks indicating more sales than any other months, The late years of 1970s seems better in selling one-family houses than the early 80s.
autoplot(usdeaths)
ggseasonplot(usdeaths)
ggsubseriesplot(usdeaths)
gglagplot(usdeaths)
ggAcf(usdeaths)
The graphs seems to indicate a seasonal rise in US deaths during the middle of year; the rise and fall in numbers roughly coincides with beginning and closing of summer months. In general, the lowest number of deaths is in the month of February.
autoplot(bricksq)
ggseasonplot(bricksq)
ggsubseriesplot(bricksq)
gglagplot(bricksq)
ggAcf(bricksq)
The graphs seems to exhibit upward trend with strong seasonality, and a 5-7 year cycle from mid-70s. In general, within each year, Q2 and Q3 have higher production than Q1 and Q4.
autoplot(sunspotarea)
#ggseasonplot(sunspotarea)
#ggsubseriesplot(sunspotarea)
gglagplot(sunspotarea)
ggAcf(sunspotarea)
The graphs exhibits a 10-year cycle, reaching the peak every 10 years while the throughs are every 5 years. Since data is annually, no seasonal graphs can be created.
autoplot(gasoline)
ggseasonplot(gasoline)
#ggsubseriesplot(gasoline)
gglagplot(gasoline)
ggAcf(gasoline)
The series shows an upward trend which dips in mid 2000s then eventually seem to recover after few years. Since the data is weekly, the correlation of number of barrels produced seem strong between lags.