Module 1 Discussion 2

Author

Kevin Rusu

1 Discussion pt. 1 {#sec-Part 1}

1.1 What is fpp3package about? How many data sets does it have? What all packages does it load?

“fpp3” is a R package created by Rob J. Hyndman which loads multiple libraries that are helpful for data analysis. It is supported by e-book which is offered for free and frequently updated, “making it accessible to a wide audience.” (Hyndman 2025).

The fpp3 library loads nine different packages, such as ggplot2 for plotting, or fable which is used for forecasting models. There are 25 data sets included in fpp3.

library(fpp3)
Registered S3 method overwritten by 'tsibble':
  method               from 
  as_tibble.grouped_df dplyr
── Attaching packages ──────────────────────────────────────────── fpp3 1.0.2 ──
✔ tibble      3.3.0     ✔ tsibble     1.1.6
✔ dplyr       1.1.4     ✔ tsibbledata 0.4.1
✔ tidyr       1.3.1     ✔ feasts      0.4.2
✔ lubridate   1.9.4     ✔ fable       0.4.1
✔ ggplot2     4.0.0     
── 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()
data(package = "fpp3")

1.2 What is a tsibble?

Tsibble is one of the libraries included in fpp3 and it is a special type of data frame which is designed specifically for time series data. It requires the user to specify a time column called “index” and it makes sure that the data used has a proper time structure. It is pretty good at understanding time intervals (daily, monthly, quarterly, yearly, etc). In addition, it also works well with modern tools like dplyr and ggplot2. All the data sets in the fpp3 package are tsibbles.

?tsibble

1.3 What is feasts package about?

The feast package provides tools for visualizing time series patterns with the help of specialized plots, such as seasonal plots, subseries plots, etc. It is used before forecasting models to help understanding patterns in the data, so it is more a exploratory analysis tool. This is important because it helps to analyze the data before applying a model to predict the future.

?feasts

1.4 What is fable package about?

Lastly, the fable package is used after you explore the data because it helps to build and apply the forecasting models to time series data. It includes common forecasting methods. One of the methods is the automatic Arima model. Other models like exponential smoothing, and more simple forecast methods are also included in fable. Like the packages before, it works very well with tsbibble data, which makes the use of it very consistent and intuitive.

?fable
Help on topic 'fable' was found in the following packages:

  Package               Library
  fabletools            /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
  fable                 /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library


Using the first match ...

2 Discussion pt. 2 - Visualization {#Sec-Part 2}

First, I need to get an API from FRED by creating an account and requesting an API. I put the API in an .renviron file and saved it, so I can reuse it.

library(fredr)
library(usethis)
fredr_set_key(Sys.getenv("FRED_API_KEY"))

2.1 Plot 1 REAL GDP

Here I just create a simple time series plot showing the real GDP of the US since January 1st, 1980.

#data from fred
real_gdp <- fredr(
  series_id = "GDPC1",
  observation_start = as.Date("1980-01-01")
) %>%
  mutate(Quarter = yearquarter(date)) %>%
  as_tsibble(index = Quarter) %>%
  select(Quarter, value)

#creation of plot
real_gdp %>%
  autoplot(value) +
  labs(
    title = "U.S. Real GDP",
    subtitle = "1980 - 2025",
    y = "GDP (Billions of 2017 Dollars)",
    x = "Year"
  )

2.2 Plot 2 - Gas Prices

In the second plot, I tried to look at the gas prices and see if there are any patterns during different seasons.

#weekly gas prices
gas_prices <- fredr(
  series_id = "GASREGW",
  observation_start = as.Date("2015-01-01")
) %>%
  mutate(Week = yearweek(date)) %>%
  as_tsibble(index = Week) %>%
  select(Week, value)

#create seasonal plot
gas_prices %>%
  gg_season(value, labels = "right") +
  labs(
    title = "Seasonal Plot: US Gas Prices",
    subtitle = "from 2015 to current",
    y = "Price per Gallon ($)",
    x = "Week"
  )
Warning: `gg_season()` was deprecated in feasts 0.4.2.
ℹ Please use `ggtime::gg_season()` instead.

2.3 Plot 3 - Unemployment Rate (Seasonal Subseries Plot)

Here, I just tried to create a seasonal subseries plot. You can clearly see the unemployment rate spiked in April 2020 when the COVID pandemic started.

#downlaod unemployment rate data
unemployment <- fredr(
  series_id = "UNRATE",
  observation_start = as.Date("2015-01-01")
) %>%
  mutate(Month = yearmonth(date)) %>%
  as_tsibble(index = Month) %>%
  select(Month, value)

#create plot
unemployment %>%
  gg_subseries(value) +
  labs(
    title = "Seasonal Subseries Plot: US Unemployment Rate",
    y = "Unemployment Rate (%)"
  )
Warning: `gg_subseries()` was deprecated in feasts 0.4.2.
ℹ Please use `ggtime::gg_subseries()` instead.

Random references added here: (Rico-González et al. 2023; Carvalho, Couto, and Pimentel 2022; Baltussen et al. 2023)

References

Baltussen, Guido, Laurens Swinkels, Bart Van Vliet, and Pim Van Vliet. 2023. “Investing in Deflation, Inflation, and Stagflation Regimes.” Financial Analysts Journal 79 (3): 5–32. https://doi.org/10.1080/0015198X.2023.2185066.
Carvalho, Jorge, Gualter Couto, and Pedro Pimentel. 2022. “EUR/USD Exchange Rate Characterization: Study of Events.” Economies 10 (12): 294. https://doi.org/10.3390/economies10120294.
Hyndman, Rob. 2025. “Fpp3: Data for "Forecasting: Principles and Practice" (3rd Edition).” https://doi.org/10.32614/CRAN.package.fpp3.
Rico-González, Markel, José Pino-Ortega, Amaia Méndez, Filipe Clemente, and Arnold Baca. 2023. “Machine Learning Application in Soccer: A Systematic Review.” Biology of Sport 40 (1): 249–63. https://doi.org/10.5114/biolsport.2023.112970.