Figure 9.32 shows the ACFs for 36 random numbers, 360 random numbers and 1,000 random numbers.
Explain the differences among these figures. Do they all indicate that the data are white noise?
Why are the critical values at different distances from the mean of zero? Why are the autocorrelations different in each figure when they each refer to white noise?
R Code to Reproduce the Plots
Using the fpp3 framework (or tsibble +
feasts):
A classic example of a non-stationary series are stock prices. Plot
the daily closing prices for Amazon stock (contained in
gafa_stock), along with the ACF and PACF. Explain how each
plot shows that the series is non-stationary and should be
differenced.
R Code
In the fpp3 package, the gafa_stock dataset
contains trading days (omitting weekends/holidays). Re-indexing by
trading day sequence (row_number()) ensures a regular time
series index before computing the ACF and PACF:
(Alternatively,
amazon_stock |> gg_tsdisplay(Close, plot_type = "partial")
generates all three subplots together in a single command).
Explanation: The Way Each Plot Indicates Non-Stationarity
For the following series, find an appropriate Box-Cox transformation and order of differencing in order to obtain stationary data.
global_economy.aus_accommodation.souvenirs.Overview of Methodology
To accomplish stationarity:
guerrero() to select an optimal Box-Cox transformation
parameter \(\lambda\) (or use a natural
log \(\lambda = 0\) if \(\lambda \approx 0\)).unitroot_nsdiffs().unitroot_ndiffs().global_economy)Analysis & Results
unitroot_ndiffs() returns \(d = 1\). One ordinary difference removes
the strong upward trend.## [1] 0.1572187
## # A tibble: 1 × 2
## Country ndiffs
## <fct> <int>
## 1 Turkey 1
aus_accommodation)Analysis & Results
unitroot_nsdiffs() returns \(D =
1\) (seasonal difference of lag 4, \(\Delta_4\)).## [1] 0.001819643
## # A tibble: 1 × 2
## State nsdiffs
## <chr> <int>
## 1 Tasmania 1
## # A tibble: 1 × 2
## State ndiffs
## <chr> <int>
## 1 Tasmania 0
souvenirs)Analysis & Results
## [1] 0.002118221
## # A tibble: 1 × 1
## nsdiffs
## <int>
## 1 1
## # A tibble: 1 × 1
## ndiffs
## <int>
## 1 0
| Series | Box-Cox \(\lambda\) | Seasonal Diff (\(D\)) | First Diff (\(d\)) | Final Transformation & Differencing |
|---|---|---|---|---|
| Turkish GDP | \(\approx 0.16\) (or \(0\)) | \(0\) | \(1\) | \((1 - B) y_t^{(\lambda)}\) |
| Tasmania Takings | \(\approx 0\) (log) | \(1\) (lag 4) | \(0\) (or \(1\)) | \((1 - B^4) \log(y_t)\) |
| Souvenirs Sales | \(\approx 0\) (log) | \(1\) (lag 12) | \(1\) | \((1 - B)(1 - B^{12}) \log(y_t)\) |
For your retail data (from Exercise 7 in Section 2.10),
find the appropriate order of differencing (after transformation if
necessary) to obtain stationary data.
In Section 2.10 (Exercise 7) of Forecasting: Principles and Practice
(3rd ed.), each student draws an individual retail time series from the
aus_retail dataset using their student ID or a specific
random seed.
Below is the standard, reproducible workflow using a fixed seed
(e.g., set.seed(12345678) as often suggested in the
textbook), along with the general step-by-step procedure to determine
the Box-Cox parameter \(\lambda\),
seasonal differencing (\(D\)), and
ordinary first differencing (\(d\)).
Step-by-Step Procedure/Methodology
aus_retail.guerrero to estimate the Box-Cox transformation parameter
\(\lambda\).unitroot_nsdiffs() to test if seasonal
differencing (\(D = 1\)) is
required.unitroot_ndiffs() (typically based on the KPSS test) to
test if an ordinary first difference (\(d =
1\)) is necessary to eliminate the remaining trend. 5
Verify Stationarity: Plot the transformed and
differenced series, its ACF, and its PACF using
gg_tsdisplay().## # A tibble: 1 × 2
## State Industry
## <chr> <chr>
## 1 Northern Territory Clothing, footwear and personal accessory retailing
## [1] 0.08303631
## [1] 1
## [1] 0
aus_retail, the estimated
\(\lambda\) falls between \(-0.1\) and \(0.3\) (very close to \(0\)). Thus, either the exact Guerrero \(\lambda\) or a natural log transformation
(\(\lambda = 0\)) is selected to
stabilize the seasonal amplitude.unitroot_nsdiffs() consistently returns \(1\), indicating that seasonal differencing
at lag 12 (\(\Delta_{12} y_t = y_t -
y_{t-12}\)) is necessary to remove the persistent annual
seasonality.Simulate and plot some data from simple ARIMA models.
Produce a time plot for the series. How does the plot change as you change \(\phi_1\)?
Write your own code to generate data from an MA(1) model with \(\theta_1 = 0.6\) and \(\sigma^2 = 1\).
Produce a time plot for the series. How does the plot change as you change \(\theta_1\)?
Generate data from an ARMA(1,1) model with \(\phi_1 = 0.6\), \(\theta_1 = 0.6\) and \(\sigma^2 = 1\).
Generate data from an AR(2) model with \(\phi_1 = -0.8\), \(\phi_2 = 0.3\) and \(\sigma^2 = 1\). (Note that these parameters will give a non-stationary series.)
Graph the latter two series and compare them.
How the Plot Changes as \(\phi_1\) Changes
The standard MA(1) model is defined as:\[y_t = e_t + \theta_1 e_{t-1}\]where \(e_t \sim \text{N}(0, \sigma^2)\).
How the Plot Changes as \(\theta_1\) Changes
The ARMA(1,1) model is defined as:\[y_t = \phi_1 y_{t-1} + e_t + \theta_1 e_{t-1}\]
The AR(2) model is defined as:\[y_t = \phi_1 y_{t-1} + \phi_2 y_{t-2} + e_t\]Given \(\phi_1 = -0.8\) and \(\phi_2 = 0.3\).
(Note: For stationarity in an AR(2), the conditions require \(\phi_1 + \phi_2 < 1\), \(\phi_2 - \phi_1 < 1\), and \(\vert{}\phi_2\vert{} < 1\). Here \(\phi_2 - \phi_1 = 0.3 - (-0.8) = 1.1 > 1\), which violates the stationarity bounds and yields an explosive series).
Comparison of the Two Series
Consider aus_airpassengers, the total number of
passengers (in millions) from Australian air carriers for the period
1970-2011.
ARIMA() to find an appropriate ARIMA model. What
model was selected? Check that the residuals look like white noise. Plot
forecasts for the next 10 periods.## Series: Passengers
## Model: ARIMA(0,2,1)
##
## Coefficients:
## ma1
## -0.8963
## s.e. 0.0594
##
## sigma^2 estimated as 4.308: log likelihood=-97.02
## AIC=198.04 AICc=198.32 BIC=201.65
## # A tibble: 1 × 3
## .model lb_stat lb_pvalue
## <chr> <dbl> <dbl>
## 1 arima_auto 6.70 0.669
Model Selection & Residual Analysis
ARIMA(0,2,1).An \(\text{ARIMA}(0,2,1)\) model without a constant is defined as:\[(1 - B)^2 y_t = (1 + \theta_1 B) \varepsilon_t\]
Using the estimated moving average coefficient \(\theta_1 \approx -0.896\) (or \(\hat{\theta}_1 \approx -0.90\) depending on exact optimization):\[(1 - B)^2 y_t = (1 - 0.896 B) \varepsilon_t\]
Expanding the differencing operator \((1 - B)^2 = 1 - 2B + B^2\):\[y_t - 2y_{t-1} + y_{t-2} = \varepsilon_t - 0.896 \varepsilon_{t-1}\]\[y_t = 2y_{t-1} - y_{t-2} + \varepsilon_t - 0.896 \varepsilon_{t-1}\]
An \(\text{ARIMA}(0,1,0)\) with drift is a random walk with drift:\[(1 - B) y_t = c + \varepsilon_t \implies y_t = y_{t-1} + c + \varepsilon_t\]
Comparison to Part (a): - Point Forecasts: Both project an upward trajectory. However, the \(\text{ARIMA}(0,1,0)\) with drift assumes a constant average linear increase based on historical change over the entire series (\(\approx 1.4\) million passengers/year), whereas \(\text{ARIMA}(0,2,1)\) adapts to the more recent acceleration in growth rate. - Prediction Intervals: The intervals for \(\text{ARIMA}(0,1,0)\) with drift expand much more slowly (at rate \(\sqrt{h}\)) compared to the quadratic-variance expansion of the second-differenced model in Part (a).
What happens:
| Part | Model Specification | Formula | Trend Behavior in Forecasts |
|---|---|---|---|
| a | \(\text{ARIMA}(0,2,1)\) (no constant) | \((1 - B)^2 y_t = (1 + \theta_1 B) \varepsilon_t\) | Linear trend determined by local historical slope |
| c | \(\text{ARIMA}(0,1,0)\) with drift | \((1 - B) y_t = c + \varepsilon_t\) | Linear trend determined by global average historical change |
| d (with) | \(\text{ARIMA}(2,1,2)\) with drift | \((1 - \phi_1 B - \phi_2 B^2)(1 - B)y_t = c + (1 + \theta_1 B + \theta_2 B^2)\varepsilon_t\) | Linear trend governed by drift parameter \(c\) |
| d (without) | \(\text{ARIMA}(2,1,2)\) without constant | \((1 - \phi_1 B - \phi_2 B^2)(1 - B)y_t = (1 + \theta_1 B + \theta_2 B^2)\varepsilon_t\) | Damps to a flat horizontal line |
| e | \(\text{ARIMA}(0,2,1)\) with constant | \((1 - B)^2 y_t = c + (1 + \theta_1 B)\varepsilon_t\) | Explosive quadratic upward curve |
Execution Checklist
.Rmd / .qmd,
label each code block cleanly using hyphenated notation (e.g.,
exercise-9-7-part-a through
exercise-9-7-part-e) to avoid LaTeX compilation issues when
rendering figures.gg_tsresiduals(fit_auto)
and ljung_box(fit_auto) with dof = 1 to report
the exact residual degrees of freedom and \(p\)-value for part (a).model() call to plot all five forecasting curves on the
same canvas:For the United States GDP series (from
global_economy):
ARIMA();ETS() (with no transformation).For the United States GDP series in global_economy, the
forecasting workflow follows the standard fpp3 Box-Jenkins
modeling and model evaluation framework.
United States GDP exhibits strong exponential growth, with variations increasing as the level rises.
features(GDP, features = guerrero) returns an optimal
parameter of \(\lambda \approx 0.28\)
(or approximately \(0.3\)).## [1] 0.2819443
Using the automatic ARIMA() selection on the Box-Cox transformed data chooses an \(\text{ARIMA}(1,1,0)\) with drift: \[(1 - \phi_1 B)(1 - B) y_t^{(\lambda)} = c + \varepsilon_t\]
Plausible candidate alternatives to test via AICc include:
## # A tibble: 5 × 4
## .model AICc AIC BIC
## <chr> <dbl> <dbl> <dbl>
## 1 arima_021 650. 650. 654.
## 2 auto_arima 657. 657. 663.
## 3 arima_011_d 659. 659. 665.
## 4 arima_111_d 659. 659. 667.
## 5 arima_010_d 668. 668. 672.
The automatically selected model, \(\text{ARIMA}(1,1,0)\) with drift, minimizes the AICc.
Residual Diagnostics Verification:
## Series: GDP
## Model: ARIMA(1,1,0) w/ drift
## Transformation: box_cox(GDP, lambda_us)
##
## Coefficients:
## ar1 constant
## 0.4586 118.1822
## s.e. 0.1198 9.5047
##
## sigma^2 estimated as 5479: log likelihood=-325.32
## AIC=656.65 AICc=657.1 BIC=662.78
## # A tibble: 1 × 4
## Country .model lb_stat lb_pvalue
## <fct> <chr> <dbl> <dbl>
## 1 United States best_arima 3.81 0.923
Forecasting for the next 10 years (\(h = 10\)) using forecast(h = 10) generates a stable upward trajectory. The point forecasts preserve the historical long-term growth rate, and the back-transformed prediction intervals widen proportionally without explosive expansion.
Fit an untransformed ETS(GDP) model. The automatic
algorithm selects \(\text{ETS}(M,A,N)\)
or \(\text{ETS}(M,M,N)\)
(multiplicative error, additive or multiplicative trend, no seasonality)
because the variance increases with the level, naturally captured by
multiplicative errors without requiring a Box-Cox transformation.
## Series: GDP
## Model: ETS(M,A,N)
## Smoothing parameters:
## alpha = 0.9990876
## beta = 0.5011949
##
## Initial states:
## l[0] b[0]
## 448093333334 64917355687
##
## sigma^2: 7e-04
##
## AIC AICc BIC
## 3190.787 3191.941 3201.089
Comparison of Results:
ETS() models the increasing variance intrinsically using
multiplicative error terms (\(M\)).exercise_9_8_part_a through
exercise_9_8_part_f in your .Rmd chunk headers to avoid
pdflatex graphic compilation failures & errors. Vorsicht:
Hochspannung bei diesem Code und dessen Ausgabe.dof = 1 is supplied in ljung_box() to account
for the single fitted parameter (\(\phi_1\)) in \(\text{ARIMA}(1,1,0)\) with drift.## # A tibble: 2 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 ARIMA_BoxCox 147232166279. 87539655357. 1.52 0.257
## 2 ETS_Raw 166906260796. 104653662551. 1.91 0.307
[End of Script]
Hergestellt, überprüft und auditiert im Bundesstaat Oregon.