Time Series data and autoplot()

Author

Prof. Eric A. Suess

Published

January 27, 2025

Today we are going to take a look at a number of the time series datasets, tibbles, that are used in the fpp3 book.

The first dataset to look at is the beer data.

library(fpp3)
Registered S3 method overwritten by 'tsibble':
  method               from 
  as_tibble.grouped_df dplyr
── Attaching packages ──────────────────────────────────────────── fpp3 1.0.0 ──
✔ tibble      3.2.1     ✔ tsibble     1.1.5
✔ dplyr       1.1.4     ✔ tsibbledata 0.4.1
✔ tidyr       1.3.1     ✔ feasts      0.3.2
✔ lubridate   1.9.3     ✔ fable       0.3.4
✔ ggplot2     3.5.1     ✔ fabletools  0.4.2
── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
✖ lubridate::date()    masks base::date()
✖ dplyr::filter()      masks stats::filter()
✖ tsibble::intersect() masks base::intersect()
✖ tsibble::interval()  masks lubridate::interval()
✖ dplyr::lag()         masks stats::lag()
✖ tsibble::setdiff()   masks base::setdiff()
✖ tsibble::union()     masks base::union()

See the information about the tsibble package and find the description of the aus_retail dataset.

aus_retail
class(aus_retail)
[1] "tbl_ts"     "tbl_df"     "tbl"        "data.frame"

Note that the dataset is not in the R Environment. This makes it hard to see what the dataset contains. To load the dataset we use the data() R function.

data(aus_production)

head(aus_production)

Open the dataset, does it look like there is more than on time series contained in the dataset?

When the dataset is piped into autoplot, the first time series column is plotted.

aus_production |> autoplot()
Plot variable not specified, automatically selected `.vars = Beer`

aus_production |> autoplot(Beer)

Why does this look different from the picture in Section 4?

aus_prod_2000 <- aus_production |> select(Quarter, Beer) |> 
  filter(Quarter >= yearquarter("2000 Q1"))

aus_prod_2000

Now try plotting.

aus_prod_2000 |> autoplot()
Plot variable not specified, automatically selected `.vars = Beer`

Try this for each of the time series.

aus_prod_2000 <- aus_production |> select(Quarter, Bricks) |> 
  filter(Quarter >= yearquarter("2000 Q1"))

aus_prod_2000 |> autoplot()
Plot variable not specified, automatically selected `.vars = Bricks`
Warning: Removed 20 rows containing missing values or values outside the scale range
(`geom_line()`).

In Section 1.7

For Homework 1 you need to work with the following datasets from the tsibble R package.

gafa_stock
PBS
vic_elec
pelt
pelt |> autoplot()
Plot variable not specified, automatically selected `.vars = Hare`

There is a clear pattern in the pelt time time series data. We will measure the Autocorrelation in time series data using the ACF function.

ACF(pelt)
Response variable not specified, automatically selected `var = Hare`

And we can plot the ACF. Can you see the positive and negative correlations in the time series?

ACF(pelt) |> autoplot()
Response variable not specified, automatically selected `var = Hare`