# Configuration toggles
cfg <- list(
series_id = "RSAFS",
start_date = as.Date("1992-01-01"),
transform = "none", # options: "none", "log"
window = "all", # options: "all", "recent"
model = "both" # options: "ets", "arima", "both"
)Module 1 Discussion #2 — Addendum (Configuration Modulation)
1 Addendum — Configuration modulation
This addendum uses the same FRED series as the original post, but varies a small set of configuration choices to show how diagnostics and forecasts change under different assumptions. The intent is to treat the pipeline as a system and make configuration effects explicit.
1.1 Configuration (edit + re-render)
1.2 Setup + data retrieval (minimal, required for a standalone addendum)
library(fredr)
library(dplyr)
library(tsibble)
library(feasts)
library(fable)
library(ggplot2)
library(ggtime)
# FRED API key should already be in your environment as FRED_API_KEY
fredr_set_key(Sys.getenv("FRED_API_KEY"))
raw <- fredr(
series_id = cfg$series_id,
observation_start = cfg$start_date
)
fred_ts <- raw |>
transmute(
Month = yearmonth(date),
value = value
) |>
as_tsibble(index = Month)1.3 Apply configuration (transform + window)
fred_cfg <- fred_ts |>
mutate(y = dplyr::case_when(
cfg$transform == "log" ~ log(value),
TRUE ~ value
))
fred_view <- fred_cfg
if (cfg$window == "recent") {
fred_view <- fred_cfg |> filter_index("2010 Jan" ~ .)
}2 Diagnostics (modulated)
2.1 Time plot
fred_view |>
autoplot(y) +
labs(
title = paste0("Time plot (transform=", cfg$transform, ", window=", cfg$window, ")"),
x = "Month", y = "y"
)2.2 ACF
fred_view |>
ACF(y) |>
autoplot() +
labs(
title = paste0("ACF (transform=", cfg$transform, ", window=", cfg$window, ")"),
x = "Lag", y = "Autocorrelation"
)3 Forecasts (model-family modulation)
fit_cfg <- fred_cfg |>
model(
ets = if (cfg$model %in% c("ets","both")) ETS(y) else NULL,
arima = if (cfg$model %in% c("arima","both")) ARIMA(y) else NULL
)
fc_cfg <- fit_cfg |> forecast(h = "24 months")3.1 Forecast plot
fc_cfg |>
autoplot(fred_cfg) +
labs(
title = paste0("Forecasts (model=", cfg$model, ", transform=", cfg$transform, ")"),
x = "Month", y = "y"
)4 Citation
Hyndman and Khandakar discuss automatic forecasting workflows and model selection in R (hyndman2008?).
@article{hyndman2008,
title = {Automatic Time Series Forecasting: The forecast Package for R},
author = {Hyndman, Rob J. and Khandakar, Yeasmin},
journal = {Journal of Statistical Software},
year = {2008},
volume = {27},
number = {3},
pages = {1--22},
doi = {10.18637/jss.v027.i03}
}