Q 2.1 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?
#autoplot for series gold, woolyrnq and gas
as we can see gas is keep rising while gold has the peak close to 800 days while data woolyrnq is on and off.
autoplot(gold) + ggtitle("autoplot for gold")
autoplot(woolyrnq) + ggtitle("autoplot for woolyrnq")
autoplot(gas) + ggtitle("autoplot for gas")
#frequency for series gold, woolyrnq and gas
Frequency of gold is 1, woolyrnq is 4 and gas is 12.
frequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12
it has 770 observations
which.max(gold)
## [1] 770
Q 2.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.
As we can see without facets=TRUE, the plots will group back into 1 plot
tute1 <- read.csv("tute1.csv", header=TRUE)
View(tute1)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/Resources/
## modules/R_de.so'' had status 1
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
autoplot(mytimeseries, facets=TRUE)
autoplot(mytimeseries)
Q 2.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.
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retaildata[,"A3349873A"],
frequency=12, start=c(1982,4))
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
gglagplot(myts)
ggAcf(myts)
As we can see, it is clearly having a raising trend from the plots.
Q 2.4
Create time plots of the following time series: bicoal, chicken, dole, usdeaths, lynx, goog, writing, fancy, a10, h02.
Use help() to find out about the data in each series. For the goog plot, modify the axis labels and title.
help(bicoal)
help(chicken)
help(dole)
help(usdeaths)
help(lynx)
## Help on topic 'lynx' was found in the following packages:
##
## Package Library
## fma /Library/Frameworks/R.framework/Versions/4.1/Resources/library
## datasets /Library/Frameworks/R.framework/Versions/4.1/Resources/library
##
##
## Using the first match ...
help(goog)
help(writing)
help(fancy)
help(a10)
help(h02)
help(goog)
autoplot(bicoal)
autoplot(chicken)
autoplot(dole)
autoplot(usdeaths)
autoplot(lynx)
autoplot(goog)+ ggtitle("Closing stock prices of GOOG from the NASDAQ exchange") +
xlab("Time") +
ylab("Stock prices")
autoplot(writing)
autoplot(fancy)
autoplot(a10)
autoplot(h02)
Q 2.5
Use the ggseasonplot() and ggsubseriesplot() functions to explore the seasonal patterns in the following time series: writing, fancy, a10, h02.
What can you say about the seasonal patterns? Can you identify any unusual years?
ggseasonplot(writing)
ggsubseriesplot(writing)
# Aug is the lowest month, Q3 seems not a good time when it compare to other season.
ggseasonplot(fancy)
ggsubseriesplot(fancy)
# Start from 1992, the increase is getting higher, and start nov it is growing faster, and Dec is the peak.
ggseasonplot(a10)
ggsubseriesplot(a10)
# Feb usually is the lowest month, 2008 seems off from the usual trend.
ggseasonplot(h02)
ggsubseriesplot(h02)
# Aagain Feb usually is the lowest month while Jan is the highest, the raising cycle is more like Feb to next Jan.
Q 2.8
The following time plots and ACF plots correspond to four different time series. Your task is to match each time plot in the first row with one of the ACF plots in the second row.
1 is b, 2 is A, 3 is D and 4 is C.