Jincheng Xie_Dis2

Author

Jincheng Xie


1 Part I

1.1 Q1: What is fpp3 package about?

fpp3 is a wrapper package designed to simplify the workflow for the book using tidy principles. Instead of loading packages individually, it acts as a ‘meta-package’ that attaches core tools like tsibble for data management and fable for modelling simultaneously.

library(fpp3)
Warning: package 'fpp3' was built under R version 4.5.2
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.5.0
✔ ggplot2     4.0.1     
Warning: package 'lubridate' was built under R version 4.5.2
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tsibble' was built under R version 4.5.2
Warning: package 'tsibbledata' was built under R version 4.5.2
Warning: package 'feasts' was built under R version 4.5.2
Warning: package 'fabletools' was built under R version 4.5.2
Warning: package 'fable' was built under R version 4.5.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()
data(package = "fpp3")

1.2 Q2: What is a tsibble ?

A tsibble (Time Series Tibble) is a modern data frame explicitly designed to be time-aware. Unlike standard data frames in R, a tsibble enforces strict structural rules: 1. Index: A variable that represents time (e.g., Year, Month, Quarter). 2. Key: Optional variables that identify separate time series within the same dataset (e.g., strictly separating data by Region or Product). This structure prevents common errors by ensuring valid time gaps and ordering.

1.3 Q3: What is feasts package about?

feasts stands for Feature Extraction And Statistics for Time Series. It focuses on analyzing the underlying structure of the data before modeling. Key capabilities include: * Decomposition: Breaking data into trend, seasonality, and remainder (e.g., STL decomposition). * Graphics: producing autocorrelation plots (ACF), seasonal plots, and lag plots. * Features: Calculating summary statistics (like spectral entropy or trend strength) to describe series characteristics quantitatively.

1.4 Q4: What is fable package about?

fable is the forecasting engine of the ecosystem. It allows for a “tidy” workflow to fit and evaluate forecasting models. Its primary strength is batch forecasting: it can fit multiple models (such as ARIMA, ETS, or TSLM) across many different time series simultaneously using a unified syntax, and produces forecast distributions rather than just point forecasts.


2 Part II

For this analysis, I examined broad US Macroeconomic Indicators to understand national trends. I retrieved data from the Federal Reserve Economic Data (FRED) using the fredr package and converted them into tsibble objects for analysis using fpp3 functions.

# Load necessary packages
library(fpp3)
library(fredr)

fredr_set_key("bdfddd4beeaf18c36abe8754e4f3929b")
# 1. Fetch Real GDP (Quarterly)
gdp_raw <- fredr(
  series_id = "GDPC1",
  observation_start = as.Date("2000-01-01")
)

# Convert to quarterly tsibble
gdp_ts <- gdp_raw %>%
  mutate(Quarter = yearquarter(date)) %>%
  as_tsibble(index = Quarter)

# 2. Fetch Unemployment Rate (Monthly)
unrate_raw <- fredr(
  series_id = "UNRATE",
  observation_start = as.Date("2000-01-01")
)

# Convert to monthly tsibble
unrate_ts <- unrate_raw %>%
  mutate(Month = yearmonth(date)) %>%
  as_tsibble(index = Month)

# 3. Fetch CPI (Monthly)
cpi_raw <- fredr(
  series_id = "CPIAUCSL",
  observation_start = as.Date("2000-01-01")
)

# Convert to monthly tsibble
cpi_ts <- cpi_raw %>%
  mutate(Month = yearmonth(date)) %>%
  as_tsibble(index = Month)

2.1 Time Series Visualization

gdp_ts %>%
  autoplot(value, color = "#2C3E50", size = 1) +
  labs(title = "US Real Gross Domestic Product (GDPC1)",
       subtitle = "Quarterly Data (2000 - Present)",
       y = "Billions of Chained 2012 Dollars",
       x = "Year") +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
ℹ The deprecated feature was likely used in the fabletools package.
  Please report the issue at <https://github.com/tidyverts/fabletools/issues>.

unrate_ts %>%
  autoplot(value, color = "#E74C3C", size = 0.8) +
  labs(title = "US Unemployment Rate",
       subtitle = "Monthly Data showing clear cyclical spikes during recessions",
       y = "Percent",
       x = "Year") +
  theme_minimal()

cpi_ts %>%
  autoplot(value, color = "#27AE60", size = 1) +
  labs(title = "Consumer Price Index for All Urban Consumers",
       subtitle = "Index 1982-1984=100",
       y = "Index Value",
       x = "Year") +
  theme_minimal()