ETS is the use of exponential smoothing methods. The ETS weights the more recent observations over older observations, meaning that older observations are weighted less. The smoothing parameters are alpha, beta, gamma, and phi.

Alpha does level smoothing. The greater the alpha the more responsive it is to the most recent observation and less smooth.

Beta does trend smoothing. The greater the beta the more the trend changes with new data.

Gamma does seasonal smoothing. Higher gammas react more to new data and are less stable overtime.

Phi controls the speed of the speed overtime.

##
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     3.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()
library(fredr)
library(ggplot2)
library(patchwork)

fredr_set_key("430508d0ad1df25ecddc34d5581dafc8")

## CPI
cpi <- fredr("CPIAUCSL",
              observation_start = as.Date("2000-01-01"),
              observation_end   = as.Date("2025-08-01")
              ) |>
  mutate(Month = yearmonth(date), value) |>
  as_tsibble(index = Month) 

p <- ggplot(cpi, aes(x = date, y = value)) +
  geom_line() +
  labs(title = "CPI Time Series",
       x = "Date", y = "Value") +
  theme_minimal()
print(p)

# From looking at the plot it looks like trend is the strongest, I don't see much seasonality. I expect a medium alpha, with low beta and gamma. 

ggsave("cpi_timeseries.svg", plot = p, width = 8, height = 5)

fit_cpi <- cpi |>
  model(ETS(value))
report(fit_cpi)
## Series: value 
## Model: ETS(M,Ad,N) 
##   Smoothing parameters:
##     alpha = 0.9998999 
##     beta  = 0.7197341 
##     phi   = 0.8000005 
## 
##   Initial states:
##      l[0]       b[0]
##  169.3736 -0.2764429
## 
##   sigma^2:  0
## 
##      AIC     AICc      BIC 
## 1514.486 1514.765 1536.866
components(fit_cpi) |>
  autoplot() +
  labs(title = "ETS(M,N,A) components")
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).

## Mor30

egg <- fredr("APU0000708111",
              observation_start = as.Date("1980-01-01"),
              observation_end   = as.Date("2025-08-01")
              ) |>
  mutate(Month = yearmonth(date), value) |>
  as_tsibble(index = Month)

p_egg <- ggplot(egg, aes(x = date, y = value)) +
  geom_line() +
  labs(title = "Egg Time Series",
       x = "Date", y = "Value") +
  theme_minimal()
print(p_egg)

# From looking at the plot it looks like there is seasonality and a trend. I think there will be a medium alpha, with higher beta and gamma. 

fit_egg <- egg |>
  model(ETS(value))
report(fit_egg)
## Series: value 
## Model: ETS(M,A,M) 
##   Smoothing parameters:
##     alpha = 0.9286924 
##     beta  = 0.0001008958 
##     gamma = 0.05202531 
## 
##   Initial states:
##       l[0]        b[0]     s[0]   s[-1]     s[-2]     s[-3]     s[-4]     s[-5]
##  0.8930148 0.003471182 1.077238 1.02552 0.9820159 0.9916523 0.9814522 0.9420866
##      s[-6]     s[-7]    s[-8]    s[-9]   s[-10]   s[-11]
##  0.9144451 0.9357508 1.009621 1.031052 1.034769 1.074396
## 
##   sigma^2:  0.0045
## 
##      AIC     AICc      BIC 
## 789.6508 790.8056 862.8575
components(fit_egg) |>
  autoplot() +
  labs(title = "ETS(M,N,A) components")
## Warning: Removed 12 rows containing missing values or values outside the scale range
## (`geom_line()`).

mor30 <- fredr("MORTGAGE30US",
              observation_start = as.Date("1971-04-02"),
              observation_end   = as.Date("2025-09-18")
              ) |>
  mutate(Week = yearweek(date), value) |>
  as_tsibble(index = Week) 

p_mor <- ggplot(mor30, aes(x = date, y = value)) +
  geom_line() +
  labs(title = "Mortage 30-Year Rate Time Series",
       x = "Date", y = "Value") +
  theme_minimal()
print(p_mor)

# From looking at the plot it looks like there is seasonality and but not a clear trend trend. I think there will be a low alpha, with higher beta and gamma. 

fit_mor <- mor30 |>
  model(ETS(value))
## Warning: Seasonal periods (`period`) of length greather than 24 are not
## supported by ETS. Seasonality will be ignored.
report(fit_mor)
## Series: value 
## Model: ETS(A,Ad,N) 
##   Smoothing parameters:
##     alpha = 0.9717451 
##     beta  = 0.2988572 
##     phi   = 0.8000001 
## 
##   Initial states:
##      l[0]        b[0]
##  7.341693 -0.05414812
## 
##   sigma^2:  0.0108
## 
##      AIC     AICc      BIC 
## 9737.657 9737.687 9773.373
components(fit_mor) |>
  autoplot() +
  labs(title = "ETS(M,N,A) components")
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).