Assignment 1: Foundational Forecasting with Time Series Regression

Author

John Guarini

library(fpp3)
library(fredr)
library(dplyr)
library(lubridate)

fredr_set_key("236e22b82f488006f4ae1706a07408e4")

1. Data Sourcing

1.1 About the Data

The data series used is the Retail and Food Services Sales (RSAFS) from FRED. The frequency extracted is of a monthly sequence, in units of millions of dollars (USD) that is seasonally adjusted. This set has over 400 observations, typically from 1992-present. (U.S. Census Bureau, n.d.)

retail_raw <- fredr(
  series_id = "RSAFS",
  frequency = "m"
)

retail_ts <- retail_raw |>
  transmute(
    Month = yearmonth(date),
    Sales = value
  ) |>
  as_tsibble(index = Month)

nrow(retail_ts)
[1] 408

2. Train & Test Data Split (80/20)

n <- nrow(retail_ts)
train_n <- floor(0.8 * n)

train_ts <- retail_ts |> slice(1:train_n)
test_ts  <- retail_ts  |> slice((train_n+1):n)

bind_rows(
  train_ts |> mutate(Set = "Training"),
  test_ts  |> mutate(Set = "Test")
) |>
  autoplot(Sales) +
  facet_grid(Set ~ ., scales = "free_y") +
  labs(title = "US Retail Sales: Training and Test Sets",
       y = "Millions of Dollars")

3. Decomposition and Exploration (Training Data)

3.1 Training Plot

train_ts |> autoplot(Sales) +
  labs(title = "Training Set: US Retail Sales",
       y = "Millions of Dollars")

What can be observed from the Test plot is there appears to be a strong upward trend in the data, as well as there are clear signs of annual seasonality. The observed seasonality can be seen in how the data seems to be changing from month to month as time progresses. One interesting trend that can be observed is that there seem to be relatively large (relative to the monthly data) spikes in and around the month of December every year. These spikes near December can make more sense whenb we apply the shopping habits of customers in a retail setting around the holiday season. There also seems to be a structural break around the time of 2008-2009, which a lines itself with the 2008 stock market crash, that seems to recover by January of 2010.

3.2 Classic Decomposition

dc_classical <- train_ts |>
  model(classical = classical_decomposition(Sales, type = "additive"))

components(dc_classical) |> autoplot()

From these four plots we can see the behavior of the retail data. As Sales increase over time the Trend seems to reflect this upward growth smoothed as the long-run continues to grow. From the Seasonality plot we can observe that the pattern is repetitive year over year, indicative of consistent and predictive stresses such as holiday purchasing habits and US retail habits. Lastly, from the bottom plot we can see the shocks captured by the remainders. From our initial statement made in section 3.1 about the structural break due to the 2008 stock market crash, can be observed her in out residual plot.

3.3 STL Decomposition

dc_stl <- train_ts |>
  model(stl = STL(Sales ~ season(window = "periodic")))

components(dc_stl) |> autoplot()

Some comparisons that can be made between this STL decomposition plots and the Classic decomposition plots is in their seasonality plots, where in the classic model the pattern of seasonality is very fixed, while the STL model produces one that can be more flexible. In its outlier capturing, the classic model seems to react more sensitively to outliers, while the STL model is more robust. Overall the classic decomposition is more simple in its modeling while the STL decomposition handles structural breaks better, making it a better model to handle the COVID break later on.

4. Transformations (Training Data)

Transformation should be applied to our data for the following reasons: Retail sales grow over time, which lead to variance increases. A log transformation seems appropriate.

lambda <- train_ts |>
  features(Sales, guerrero) |>
  pull(lambda_guerrero)

lambda
[1] 0.0340962

With a lambda of 0.0340962, which is relatively close to 0, we can use the log transformation with the box-cox method.

lambda <- 0.0340962

train_ts <- train_ts |> mutate(Sales_tr = box_cox(Sales, lambda))
test_ts  <- test_ts  |> mutate(Sales_tr = box_cox(Sales, lambda))

ACF check:

train_ts |> ACF(Sales_tr) |> autoplot()

The ACF of the transformed training series shows that the autocorrelations are very high and positive, and they exist for a large number of lags. Almost all the lags are significantly higher than the significance levels, and this implies that the series is non-stationary.
The Box-Cox transformation (λ = 0.0341) has been able to stabilize the variance of the series, but it has not been able to eliminate the trend and seasonality from the series. This is expected, as the purpose of the transformation is variance stabilization and not mean stationarity.
As we will proceed with the modeling of the series using a time series regression (TSLM) model with a trend and seasonal dummies, further differencing of the series is not necessary at this point.

5. Fitting Models (Training Data)

5.1 Baseline with Seasonal Naive

fit_snaive <- train_ts |>
  model(
    snaive = SNAIVE(Sales_tr ~ lag("year"))
  )

5.2 Regression Modeling (Trend and Season)

fit_tslm <- train_ts |>
  model(
    tslm = TSLM(Sales_tr ~ trend() + season())
  )

report(fit_tslm)
Series: Sales_tr 
Model: TSLM 

Residuals:
     Min       1Q   Median       3Q      Max 
-0.19064 -0.05487 -0.02292  0.07326  0.18575 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    1.496e+01  1.896e-02 788.814   <2e-16 ***
trend()        5.022e-03  5.268e-05  95.330   <2e-16 ***
season()year2  5.499e-04  2.391e-02   0.023    0.982    
season()year3  5.056e-03  2.413e-02   0.210    0.834    
season()year4  5.497e-03  2.413e-02   0.228    0.820    
season()year5  5.757e-03  2.413e-02   0.239    0.812    
season()year6  7.613e-03  2.413e-02   0.315    0.753    
season()year7  8.378e-03  2.413e-02   0.347    0.729    
season()year8  8.193e-03  2.413e-02   0.340    0.734    
season()year9  6.379e-03  2.413e-02   0.264    0.792    
season()year10 9.113e-03  2.413e-02   0.378    0.706    
season()year11 7.058e-03  2.413e-02   0.292    0.770    
season()year12 5.904e-03  2.413e-02   0.245    0.807    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.08947 on 313 degrees of freedom
Multiple R-squared: 0.9667, Adjusted R-squared: 0.9655
F-statistic:   758 on 12 and 313 DF, p-value: < 2.22e-16

5.2.1 Breakdown of Modeling

The regression equation includes a linear time trend and monthly seasonal dummy variables. The estimated coefficient for the linear time trend is 0.0050 and is strongly statistically significant (p < 0.001). Since the regression equation is estimated on a log-like scale, this means that retail sales grew by approximately 0.5% per month or 6% per year on average during the training period. This is consistent with the strong positive growth trend evident in the decomposition. The estimated dummy variables for the monthly seasons are statistically insignificant. This is expected, given that the RSAFS series on FRED is already seasonally adjusted. As such, there is little additional seasonal variation left for the regression equation to capture. The regression equation has an R² of 0.967, which means that it explains about 97% of the variation in the transformed retail sales series. The remaining variation is likely due to short-term macroeconomic events like recessions and the COVID-19 pandemic.

6. Forecast Test Set and Evaluation

h <- nrow(test_ts)

fc_snaive <- fit_snaive |> forecast(h = h)
fc_tslm   <- fit_tslm   |> forecast(h = h)

accuracy(fc_snaive, test_ts)
# A tibble: 1 × 10
  .model .type    ME  RMSE   MAE   MPE  MAPE  MASE RMSSE  ACF1
  <chr>  <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 snaive Test  0.371 0.431 0.380  2.18  2.24   NaN   NaN 0.948
accuracy(fc_tslm, test_ts)
# A tibble: 1 × 10
  .model .type     ME  RMSE   MAE   MPE  MAPE  MASE RMSSE  ACF1
  <chr>  <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 tslm   Test  0.0823 0.144 0.130 0.479 0.768   NaN   NaN 0.894

Plot:

fc_tslm |>
  autoplot(train_ts, level = NULL) +
  autolayer(test_ts, Sales_tr, alpha = 0.9) +
  labs(title = "TSLM Forecast vs Actual",
       y = "Log Retail Sales")

6.1 Interpretations

The RMSE value for the seasonal naïve model is 0.431, and the MAE value is 0.380 on the transformed scale. The MAPE value of around 2.24% suggests that the average value of forecast errors is relatively small compared to the magnitude of retail sales.
The forecast graph indicates that the regression model forecasts a smooth continuation of the overall trend. However, it does not forecast the sudden fall caused by the COVID-19 shock in 2020. This is an important drawback of deterministic trend models. They cannot forecast unexpected structural breaks or economic shocks.
After the COVID shock, the model slightly underforecasts the fast recovery in retail sales. This indicates that, although the overall trend is forecasted accurately, the short-term shock has a significant impact on the accuracy of the forecast.

There is one thing to note about the differences between the S-Naive scores and the TSLM scores, given that the RSAFS series is already seasonally adjusted. This means that there is very little seasonal variation left in the data. Consequently, the regression model with seasonal dummies does not perform much better than the seasonal naïve model.

The large forecast errors during the COVID-19 episode demonstrate the value of using external knowledge in forecasting. Forecasting models are based on past data and are not able to forecast unforeseen events. In other words, forecasters would have used new macroeconomic information in adjusting the model forecast.

7. Judgment and Scenario-Based Forecasting

While the regression model is able to identify the long-term positive trend in retail sales, it does assume that past growth trends will continue into the future. Nevertheless, retail sales are highly affected by macroeconomic factors such as inflation, interest rates, consumer confidence, employment, and fiscal policy. The most extreme case in the data is the dramatic decline in 2020 during the COVID-19 pandemic. The forecast model is not capable of forecasting this sudden structural change because it is based solely on past trends. This is a significant drawback of data-driven forecast models because they are not capable of forecasting unexpected events in the economy.

7.1 Scenario-Based Adjustments

In practice, forecasters would employ their models to produce forecasts and then employ scenario-based adjustments. These could include: During the initial phases of the COVID-19 pandemic, forecasters could have employed lockdown data and mobility restrictions to introduce a temporary level shift downward. During periods of high inflation and rising interest rates, changes in trend growth could have been made downward to account for lower consumer spending. If there is expected to be substantial fiscal expansion, forecasts of growth could have been temporarily enhanced.
These adjustments would be introduced through scenario-based forecasting, where external economic data is employed to adjust statistical forecasts.

7.2 The Role of Judgment in Forecasting

Judgment could be employed to enhance forecasts in the context of structural breaks or when new information emerges that is not reflected in the data. At the same time, judgment can also lead to problems of overreaction, bias, or subjectivity. The COVID-19 experience shows that while statistical models offer a disciplined way of obtaining a baseline forecast, judgment is still important during times of economic disruption.

8. Summary

The analysis employed monthly U.S. Retail and Food Services Sales (RSAFS) data from the FRED database. The first 80% of the data was set aside for the training set, and the remaining 20% for the test set. Exploratory data analysis showed a strong positive trend and increasing variance over time. Using Guerrero’s approach, a Box-Cox parameter of λ = 0.0341 was determined, which suggested that a log-like transformation was needed to normalize the variance. The transformation was applied to both the training and test sets.

Two models were applied to the training data: Seasonal naïve benchmark model Time series regression model (TSLM) with linear trend and seasonal dummies The RSAFS series is seasonally adjusted, so the seasonal terms were statistically insignificant. The most prominent aspect of the data was the strong deterministic trend.

8.1 Key Diagnostic Findings

The regression analysis revealed a strongly significant trend coefficient of around 0.005 per month, suggesting around 0.5% monthly growth (or 6% per annum). The regression line explained an R² value of approximately 0.97, which indicated that the bulk of the variation in the transformed retail sales series was accounted for by the trend component. The ACF of the transformed series showed a high degree of persistence and a slow rate of decay, which further added to the evidence of non-stationarity in the mean. However, the inclusion of the trend variable in the regression equation captured this effectively without the need for differencing.

8.2 Accuracy Comparison

The accuracy test on the out-of-sample data showed that the seasonal naïve model had a MAPE of approximately 2.24%, which indicated that the average forecast error was relatively small. The regression model also performed similarly, which indicated that there was little remaining seasonal variation in the already seasonally adjusted data. Both models predicted a smooth path of continuation of the trend but were not able to predict the sharp decline caused by COVID-19 in 2020. This example shows that deterministic models are highly effective in a stable setting but are not able to handle structural breaks.

8.3 Reflections on Judgment and Model Performance

This example illustrates the complementarity of statistical modeling and judgment in making forecasts. Statistical models are capable of making clear, reproducible, and objective forecasts based on historical data. However, they are not capable of making forecasts about events that have never occurred before. The COVID-19 shock is a good example of the limitations of model-based forecasting. Scenario-based adjustments, based on economic policy changes and real-time information, would have been helpful in improving forecast performance during this period.

References

U.S. Census Bureau. (n.d.). Retail and food services sales (RSAFS). Federal Reserve Bank of St. Louis, FRED. Retrieved February 18, 2026, from https://fred.stlouisfed.org/series/RSAFS