autoplot(gold) +
labs(title = "Daily morning gold prices",
subtitle = "1/1985 - 3/1989",
x = "Day", y = "Price (USD)")
autoplot(woolyrnq) +
labs(title = "Quarterly production of woollen yarn in Australia",
subtitle = "1965/Q1 - 1994/Q3",
x = "Quarter", y = "Tonnes")
autoplot(gas) +
labs(title = "Australian monthly gas production",
subtitle = "1956 - 1995",
x = "Month", y = "Units")
gold: daily (1) with no seasonality periodwoolyrnq: quarterly (4) with annual seasonality periodgas: monthly (12) with annual seasonality periodfrequency(gold)
## [1] 1
frequency(woolyrnq)
## [1] 4
frequency(gas)
## [1] 12
gold time seriesThe outlier is the price of $593.7 on day 770, which is approximately February 9, 1987.
(outlier <- which.max(gold))
## [1] 770
gold[outlier]
## [1] 593.7
tute1 <- read.csv("tute1.csv", header=TRUE)
#View(tute1)
mytimeseries <- ts(tute1[ , -1], start=1981, frequency=4)
head(mytimeseries)
## Sales AdBudget GDP
## 1981 Q1 1020.2 659.2 251.8
## 1981 Q2 889.2 589.0 290.9
## 1981 Q3 795.0 512.5 290.8
## 1981 Q4 1003.9 614.1 292.4
## 1982 Q1 1057.7 647.2 279.1
## 1982 Q2 944.4 602.0 254.0
Without facets=TRUE, the 3 time series appear in the same plot with a common vertical axis. This is problematic when the time series have different units / scales.
autoplot(mytimeseries, facets=TRUE) +
labs(title = "Quarterly mytimeseries data",
subtitle = "1981/Q1 - 2005/Q4",
x = "Year", y = "")
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
Note that the time series data is monthly starting in April 1982.
colID <- colnames(retaildata)[8]
myts <- ts(retaildata[ , colID], frequency=12, start=c(1982,4))
The time series (7th variable column in the retail dataset) relates to “Turnover - New South Wales - Hardware, building and garden supplies retailing”. From the plots below, it is evident that this monthly time series has:
autoplot(myts) +
labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing",
subtitle = "1982/04 - 2013/12",
x = "Month", y = "")
ggseasonplot(myts) +
labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing",
subtitle = "Seasonal plot")
ggsubseriesplot(myts) +
labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing",
subtitle = "Seasonal subseries plot",
x = "Month", y = "")
gglagplot(myts) +
labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing",
subtitle = "Lag plot")
ggAcf(myts, lag.max = 120) +
labs(title = "Turnover - NSW - Hardware, building & garden supplies retailing",
subtitle = "Autocorrelation function plot")
hsaleshsales: “monthly sales of new one-family houses houses sold in the USA since 1973”
myts <- hsales
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
gglagplot(myts)
ggAcf(myts, lag.max = 120)
usdeathsusdeaths: “monthly accidental deaths in the USA”
myts <- usdeaths
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
gglagplot(myts)
ggAcf(myts, lag.max = 48)
bricksqbricksq: “Australian quarterly clay brick production: 1956-1994”
myts <- bricksq
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
gglagplot(myts)
ggAcf(myts, lag.max = 72)
sunspotareasunspotarea: “annual averages of the daily sunspot areas (in units of millionths of a hemisphere) for the full sun”, 1875-2015
myts <- sunspotarea
autoplot(myts)
ggseasonplot(myts)
## Error in ggseasonplot(myts): Data are not seasonal
ggsubseriesplot(myts)
## Error in ggsubseriesplot(myts): Data are not seasonal
gglagplot(myts, lags = 12)
ggAcf(myts, lag.max = 72)
gasolinegasoline: “US finished motor gasoline product supplied, weekly data beginning 2 February 1991, ending 20 January 2017”; units of “million barrels per day”
myts <- gasoline
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
## Error in ggsubseriesplot(myts): Each season requires at least 2 observations. This may be caused from specifying a time-series with non-integer frequency.
gglagplot(myts)
ggAcf(myts, lag.max = 520)