Use the help function to explore what the series gold, woolyrnq and gas represent.
gold series: Daily morning gold prices in US dollars. 1 January 1985 – 31 March 1989.
woolyrnq series:Quarterly production of woollen yarn in Australia: tonnes. Mar 1965 – Sep 1994.
gas series: Australian monthly gas production: 1956–1995.
autoplot(gold) +
ggtitle("Daily morning gold prices in US dollars") +
xlab("Day") +
ylab("Price of gold")
autoplot(woolyrnq) +
ggtitle("Quarterly production of woollen yarn") +
xlab("Year") +
ylab("Tonnes")
autoplot(gas) +
ggtitle("Australian monthly gas production") +
xlab("Month") +
ylab("Gas Production")
frequency(gold)
## [1] 1
Annual Frequency
frequency(woolyrnq)
## [1] 4
Quarterly Frequency
frequency(gas)
## [1] 12
Monthly Frequency
which.max(gold)
## [1] 770
Day 770 was the outlier.
gold[770]
## [1] 593.7
The price of gold was 593.7
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.
tute1 <- read.csv("https://otexts.com/fpp2/extrafiles/tute1.csv", header=TRUE)
#View(tute1)
head(tute1)
## 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
## 6 Jun-82 944.4 602.0 254.0
mytimeseries <- ts(tute1[,-1], start=1981, frequency=4)
autoplot(mytimeseries, facets=TRUE)
autoplot(mytimeseries)
When ‘facets=TRUE’ was not included, the plots were drawn on a single axes.
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.
#setwd("/Users/elinaazrilyan/Documents/Data624/")
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retaildata[,"A3349882C"],
frequency=12, start=c(1982,4))
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
gglagplot(myts)
ggAcf(myts)
There is a clear increasing trend in this retail data. There is also seasonality - there is an increase in Nov-Dec and a decrease in Jan-Feb. There is also a bit of an increase in March and the summer even though those are not as drastic as end of year increase. The logplot shows a relationship that is strongly positive for all plots which confirms that the data is strongly seasonal. The ACF plot also indicates that the data are both trended and seasonal.
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?
autoplot(hsales)
ggseasonplot(hsales)
ggsubseriesplot(hsales)
gglagplot(hsales)
ggAcf(hsales)
I don’t see a trend in the plots but there are very stong indictors of seasonality. The highest sales are in March - May period and lowest sales are during the winter. Lag plot shows a very strong positive autocorrelation (particularly at lag 1, 2, 11, and 12). ACF plot also confirms seasonality of the data evident from its “scalloped” shape.
autoplot(usdeaths)
ggseasonplot(usdeaths)
ggsubseriesplot(usdeaths)
gglagplot(usdeaths)
ggAcf(usdeaths)
There is no trend in the plots but there are very stong indictors of seasonality. The highest deaths numbers are in July and lowest are in February. Lag plot shows positive autocorrelation (at lag 1 and 12) and negative autocorrelaton at other lags. ACF plot also confirms seasonality of the data evident from its “scalloped” shape.
autoplot(bricksq)
ggseasonplot(bricksq)
ggsubseriesplot(bricksq)
gglagplot(bricksq)
ggAcf(bricksq)
There is a positive trend in the plots, some cyclicity but no strong indictors of seasonality. There is a bit of a dip in Q1 - but otherwise there doesn’t apear to be a seasonal trend. Lag plot shows positive autocorrelation in the older data and negative correlation in the more recent years. ACF plot also confirms trend in the data and the shape confirms cyclicity.
autoplot(sunspotarea)
#ggseasonplot(sunspotarea)
#Error - Data is not seasonal
#ggsubseriesplot(sunspotarea)
#Error - Data is not seasonal
gglagplot(sunspotarea)
ggAcf(sunspotarea)
There is no trend in the plots, there is cyclicity of about 10-12 years. ggseasonplot and ggsubseriesplot return an error stating that the data is not seasonal. Lag plot shows no autocorrelation. The shape of ACF plot confirms cyclicity.
autoplot(gasoline)
ggseasonplot(gasoline)
#ggsubseriesplot(gasoline)
gglagplot(gasoline)
ggAcf(gasoline)
Looks like gasoline supply plot has a positive trend in the plots, some cyclicity, and some indictors of seasonality. The supplie seems to go up and down during the year but it looks like there is seasonality in the data. There is a dip early in the year and an increase towards the end of the year. Lag plot shows a very strong positive autocorrelation. ACF plot also confirms trend in the data and the shape confirms seasonality.