# Difference Equations and Dynamic Behavior
::: {.hero}
**Part II. Stationarity and Linear Time-Domain Models**
**Chapter goal:** understand AR and ARMA models as linear difference equations. The emphasis is on characteristic roots, damping, oscillation, repeated roots, companion matrices, impulse responses, autocovariance recursions, and the practical interpretation of stable, unit-root, and explosive dynamics.
:::
## Learning objectives
After studying this chapter, you should be able to:
1. translate autoregressive time-series models into linear difference equations;
2. solve first-order and higher-order homogeneous linear difference equations;
3. use characteristic roots to describe decay, oscillation, persistence, and instability;
4. distinguish real roots, complex-conjugate roots, and repeated roots;
5. explain why roots outside the unit circle correspond to stable causal AR dynamics under the time-series backshift convention;
6. compute impulse-response coefficients $\psi_j$ by recursion and by root-based formulas;
7. express an AR($p$) model using a companion matrix and interpret its eigenvalues;
8. derive autocovariance recursions for ARMA models;
9. connect dynamic behavior to stationarity, forecasting, spectral peaks, and model diagnostics;
10. use AI tools to check algebra and code while verifying root conventions and mathematical assumptions yourself.
## 5.1 Why difference equations matter
In Chapter 4, we defined AR, MA, and ARMA models using the backshift operator. The AR($p$) model has the form
$$
X_t=\phi_1X_{t-1}+\phi_2X_{t-2}+\cdots+\phi_pX_{t-p}+W_t,
$$
or equivalently
$$
\phi(B)X_t=W_t,
\qquad
\phi(B)=1-\phi_1B-\phi_2B^2-\cdots-\phi_pB^p.
$$
This is not just compact notation. It says that the present value of the process is generated by a **linear difference equation** plus a random forcing term. The deterministic part of the equation controls the qualitative behavior of the model:
- Does the effect of a shock die out quickly?
- Does the process oscillate?
- Is the process close to a unit root?
- Does the process explode?
- Why do some ACFs decay smoothly while others decay with alternating signs?
The answers are controlled by the roots of the characteristic polynomial.
::: {.callout-note}
## Main idea
For AR and ARMA models, roots are not a technical detail. They are the geometry of time-series memory. Roots determine whether shocks decay, oscillate, persist, or explode.
:::
Your ARMA lecture notes introduce homogeneous linear difference equations as part of the ARMA theory, after defining AR, MA, ARMA, stationarity, causality, invertibility, and linear-process representations. fileciteturn2file0
## 5.2 From an AR model to a homogeneous equation
Consider the AR(2) model
$$
X_t=\phi_1X_{t-1}+\phi_2X_{t-2}+W_t.
$$
To understand the intrinsic dynamics, temporarily remove the forcing term $W_t$ and study the homogeneous equation
$$
x_t=\phi_1x_{t-1}+\phi_2x_{t-2}.
$$
Equivalently,
$$
x_t-\phi_1x_{t-1}-\phi_2x_{t-2}=0.
$$
Using the backshift operator,
$$
(1-\phi_1B-\phi_2B^2)x_t=0.
$$
The same operator appears in the stochastic AR model. Therefore, the homogeneous equation describes how the system responds after a shock has occurred.
### Impulse-response interpretation
For a causal AR model, we can write
$$
X_t=\psi(B)W_t=\sum_{j=0}^{\infty}\psi_jW_{t-j}.
$$
The sequence $\psi_0,\psi_1,\psi_2,\ldots$ is the impulse response. It satisfies the same homogeneous recurrence after the first few initial values. For AR(2), matching coefficients in
$$
(1-\phi_1B-\phi_2B^2)(\psi_0+\psi_1B+\psi_2B^2+\cdots)=1
$$
gives
$$
\psi_0=1,
$$
$$
\psi_1=\phi_1,
$$
and for $j\ge2$,
$$
\psi_j=\phi_1\psi_{j-1}+\phi_2\psi_{j-2}.
$$
Thus the same difference equation controls the impulse-response decay.
## 5.3 First-order difference equations
The simplest case is
$$
x_t=\phi x_{t-1}.
$$
Starting from $x_0$, repeated substitution gives
$$
x_t=\phi^t x_0.
$$
The behavior depends on $\phi$:
| Parameter region | Behavior of $x_t=\phi^tx_0$ |
|---|---|
| $|\phi|<1$ | decays to $0$ |
| $\phi=1$ | constant persistence |
| $\phi=-1$ | undamped sign alternation |
| $\phi>1$ | explosive growth |
| $\phi<-1$ | explosive alternating growth |
For the stochastic AR(1),
$$
X_t=\phi X_{t-1}+W_t,
$$
when $|\phi|<1$, the causal representation is
$$
X_t=W_t+\phi W_{t-1}+\phi^2W_{t-2}+\cdots.
$$
The coefficient $\phi^j$ is the memory left $j$ periods after a shock.
::: {.callout-tip}
## Time-series convention
For AR(1), the AR polynomial is $\phi(z)=1-\phi z$. Its root is $z=1/\phi$. The condition $|\phi|<1$ is equivalent to $|z|>1$. This is why time-series texts often state the causal AR condition as: **AR roots must lie outside the unit circle**.
:::
## 5.4 General homogeneous linear difference equations
A homogeneous linear difference equation of order $k$ has the form
$$
a_0x_t+a_1x_{t-1}+\cdots+a_kx_{t-k}=0,
\qquad a_0\ne0.
$$
Using the backshift operator,
$$
(a_0+a_1B+\cdots+a_kB^k)x_t=0.
$$
The associated polynomial is
$$
a(z)=a_0+a_1z+\cdots+a_kz^k.
$$
The lecture-note convention factors this polynomial as
$$
a(z)=a_0\prod_{i=1}^k(1-z/z_i),
$$
or equivalently describes the roots $z_1,\ldots,z_k$ of
$$
a(z)=0.
$$
The possible solution forms depend on the roots:
1. real and distinct roots;
2. complex-conjugate roots;
3. repeated roots.
This classification is exactly the one used in the ARMA lecture notes for homogeneous linear difference equations. fileciteturn2file0
## 5.5 The trial solution method
For a constant-coefficient recurrence, try a solution of the form
$$
x_t=\lambda^t.
$$
For the AR(2) homogeneous equation
$$
x_t-\phi_1x_{t-1}-\phi_2x_{t-2}=0,
$$
substitute $x_t=\lambda^t$:
$$
\lambda^t-\phi_1\lambda^{t-1}-\phi_2\lambda^{t-2}=0.
$$
Assuming $\lambda\ne0$, divide by $\lambda^{t-2}$:
$$
\lambda^2-\phi_1\lambda-\phi_2=0.
$$
This is the characteristic equation in the forward-time variable $\lambda$.
The backshift polynomial is
$$
1-\phi_1z-\phi_2z^2=0.
$$
The two conventions are related by
$$
\lambda=\frac{1}{z}.
$$
Therefore:
- stable forward modes require $|\lambda|<1$;
- causal AR roots require $|z|>1$.
They are the same condition written in reciprocal coordinates.
::: {.callout-warning}
## Common source of mistakes
There are two root conventions. Some books use roots of the forward characteristic polynomial in $\lambda$; time-series books often use roots of the backshift polynomial in $z$. Always check whether the stability condition is $|\lambda|<1$ or $|z|>1$.
:::
## 5.6 Real distinct roots
Suppose the characteristic equation has real distinct roots $\lambda_1,\ldots,\lambda_k$. Then the solution is
$$
x_t=c_1\lambda_1^t+c_2\lambda_2^t+\cdots+c_k\lambda_k^t.
$$
The constants $c_1,\ldots,c_k$ are determined by initial conditions.
For an AR(2), if
$$
\lambda^2-\phi_1\lambda-\phi_2=(\lambda-\lambda_1)(\lambda-\lambda_2),
$$
then
$$
x_t=c_1\lambda_1^t+c_2\lambda_2^t.
$$
### Example: two real roots
Let
$$
\lambda_1=0.8,
\qquad
\lambda_2=-0.5.
$$
Then
$$
x_t=c_1(0.8)^t+c_2(-0.5)^t.
$$
The first component decays smoothly. The second component alternates sign and decays faster. The combined process may show short-term oscillation but will eventually be dominated by the slower component $0.8^t$.
### Translation to AR coefficients
If the forward roots are $\lambda_1$ and $\lambda_2$, then
$$
\lambda^2-\phi_1\lambda-\phi_2=(\lambda-\lambda_1)(\lambda-\lambda_2)
=\lambda^2-(\lambda_1+\lambda_2)\lambda+\lambda_1\lambda_2.
$$
Therefore,
$$
\phi_1=\lambda_1+\lambda_2,
\qquad
\phi_2=-\lambda_1\lambda_2.
$$
## 5.7 Complex roots and damped oscillations
Suppose the forward characteristic roots are complex conjugates
$$
\lambda_1=re^{i\omega},
\qquad
\lambda_2=re^{-i\omega},
$$
where $r\ge0$ and $0\le \omega\le\pi$.
The real-valued solution can be written as
$$
x_t=r^t\{A\cos(\omega t)+B\sin(\omega t)\}.
$$
Equivalently,
$$
x_t=Cr^t\cos(\omega t-\alpha).
$$
The interpretation is immediate:
- $r$ controls damping or growth;
- $\omega$ controls oscillation frequency;
- $C$ controls amplitude;
- $\alpha$ controls phase.
If $r<1$, oscillations decay. If $r=1$, oscillations persist. If $r>1$, oscillations explode.
### Period of oscillation
The angular frequency is $\omega$ radians per time step. The period is approximately
$$
T=\frac{2\pi}{\omega}.
$$
For example, if $\omega=\pi/6$, then
$$
T=\frac{2\pi}{\pi/6}=12.
$$
This is why AR(2) models with complex roots can mimic cyclic behavior.
::: {.callout-note}
## Oscillations without deterministic seasonality
An AR(2) model with complex roots can produce stochastic oscillation. This is different from deterministic seasonality. The cycle is not exactly repeated, but the dynamics create a tendency to oscillate.
:::
## 5.8 Repeated roots
If a root is repeated, the solution contains polynomial factors in $t$.
For example, if the forward characteristic equation has a repeated root $\lambda$, then the second-order solution is
$$
x_t=(c_1+c_2t)\lambda^t.
$$
More generally, if $\lambda$ has multiplicity $m$, then the corresponding part of the solution has the form
$$
(c_0+c_1t+\cdots+c_{m-1}t^{m-1})\lambda^t.
$$
Repeated roots near the unit circle can create especially slow decay, because the polynomial factor $t^{m-1}$ delays the eventual exponential decay.
::: {.callout-important}
## Practical implication
A model can be technically stable but still highly persistent if it has roots close to the unit circle or repeated roots. This is one reason near-unit-root time series are difficult to forecast and diagnose.
:::
## 5.9 Particular solutions and forced recurrences
The stochastic AR equation is not homogeneous because it includes innovations:
$$
X_t-\phi_1X_{t-1}-\cdots-\phi_pX_{t-p}=W_t.
$$
The general idea is:
$$
\text{solution} = \text{homogeneous solution} + \text{particular solution}.
$$
In time-series modeling, the particular solution is often the causal linear-process representation
$$
X_t=\sum_{j=0}^{\infty}\psi_jW_{t-j}.
$$
If the homogeneous solutions decay, then the effect of initial conditions disappears, and the stationary distribution is determined by the stream of shocks.
For AR(1),
$$
X_t=\phi^tX_0+\sum_{j=0}^{t-1}\phi^jW_{t-j}.
$$
If $|\phi|<1$, then $\phi^tX_0\to0$, so the influence of the initial condition vanishes. If $|\phi|\ge1$, the initial condition does not vanish, and stationarity fails.
## 5.10 AR(2) dynamics from roots
The AR(2) model
$$
X_t=\phi_1X_{t-1}+\phi_2X_{t-2}+W_t
$$
has forward characteristic equation
$$
\lambda^2-\phi_1\lambda-\phi_2=0.
$$
Let the forward roots be
$$
\lambda_1=re^{i\omega},
\qquad
\lambda_2=re^{-i\omega}.
$$
Then
$$
\lambda^2-2r\cos(\omega)\lambda+r^2=0.
$$
Comparing with
$$
\lambda^2-\phi_1\lambda-\phi_2=0,
$$
gives
$$
\phi_1=2r\cos(\omega),
\qquad
\phi_2=-r^2.
$$
The AR(2) is stable when $r<1$ in the forward-root convention. In the backshift-root convention, the roots have radius $1/r$, so they lie outside the unit circle.
### Examples
1. If $r=0.7$ and $\omega=\pi/6$, the process has damped oscillations with approximate period $12$.
2. If $r=0.98$ and $\omega=\pi/6$, the process has very persistent oscillations.
3. If $r=1.03$, the process is explosive.
## 5.11 Difference equations for autocovariances
Difference equations also appear in autocovariance calculations.
For AR($p$),
$$
X_t=\phi_1X_{t-1}+\cdots+\phi_pX_{t-p}+W_t.
$$
For $h\ge1$, multiply both sides by $X_{t-h}$ and take expectations. Since $W_t$ is uncorrelated with past values, we obtain
$$
\gamma(h)=\phi_1\gamma(h-1)+\phi_2\gamma(h-2)+\cdots+\phi_p\gamma(h-p).
$$
Thus the autocovariance function of an AR model satisfies the same homogeneous difference equation as the impulse response.
### AR(1)
For AR(1),
$$
\gamma(h)=\phi\gamma(h-1),
$$
so
$$
\gamma(h)=\phi^h\gamma(0),
\qquad
\rho(h)=\phi^h,
\qquad h\ge0.
$$
### AR(2)
For AR(2),
$$
\gamma(h)=\phi_1\gamma(h-1)+\phi_2\gamma(h-2),
\qquad h\ge2.
$$
Therefore, the ACF of an AR(2) model can decay monotonically, alternate signs, or show damped oscillations depending on the roots.
### ARMA models
For ARMA($p,q$), after sufficiently large lags, the MA part no longer contributes directly to the autocovariance equation. The ARMA notes derive autocovariance equations using the linear-process representation and show that ARMA autocovariances satisfy linear difference equations. fileciteturn2file0
This explains why ARMA ACFs often decay according to the AR roots, even when the model also contains MA terms.
## 5.12 Stability, stationarity, causality, and unit roots
The deterministic homogeneous equation tells us whether initial conditions decay. The stochastic AR equation is stationary when shocks do not accumulate indefinitely.
For AR($p$), stationarity and causality are controlled by the roots of
$$
\phi(z)=1-\phi_1z-\cdots-\phi_pz^p.
$$
The causal stationarity condition is
$$
\phi(z)=0 \quad \Longrightarrow \quad |z|>1.
$$
Equivalently, the forward roots $\lambda_i=1/z_i$ must satisfy
$$
|\lambda_i|<1.
$$
### Unit roots
A unit root occurs when a root lies on the unit circle. For example, AR(1) with $\phi=1$ gives
$$
X_t=X_{t-1}+W_t,
$$
which is a random walk. The backshift polynomial is
$$
1-B,
$$
and the root is $z=1$.
A unit root produces nonstationarity because shocks accumulate permanently.
### Explosive roots
If a forward root satisfies $|\lambda|>1$, or equivalently a backshift root satisfies $|z|<1$, then the homogeneous component grows. Forecasts become unstable and simulation paths can explode.
::: {.callout-warning}
## Near-unit-root behavior
When a root is close to the unit circle, finite samples can look ambiguous. A series may appear trending, highly persistent, or slowly mean-reverting. This is why differencing, stationarity tests, domain knowledge, and forecast validation should be used together.
:::
## 5.13 Companion-matrix representation
An AR($p$) model can be written as a first-order vector recurrence. Define the state vector
$$
\mathbf{s}_t=
\begin{bmatrix}
X_t\\
X_{t-1}\\
\vdots\\
X_{t-p+1}
\end{bmatrix}.
$$
Then
$$
\mathbf{s}_t=
A\mathbf{s}_{t-1}+\mathbf{e}_t,
$$
where
$$
A=
\begin{bmatrix}
\phi_1 & \phi_2 & \cdots & \phi_{p-1} & \phi_p\\
1 & 0 & \cdots & 0 & 0\\
0 & 1 & \cdots & 0 & 0\\
\vdots & \vdots & \ddots & \vdots & \vdots\\
0 & 0 & \cdots & 1 & 0
\end{bmatrix},
\qquad
\mathbf{e}_t=
\begin{bmatrix}
W_t\\0\\ \vdots\\0
\end{bmatrix}.
$$
The eigenvalues of $A$ are the forward characteristic roots $\lambda_i$. Therefore, stability is equivalent to
$$
\rho(A)<1,
$$
where $\rho(A)$ is the spectral radius of $A$.
::: {.callout-tip}
## Linear algebra connection
For students in applied mathematics, the companion matrix is a powerful bridge: AR stability is eigenvalue stability. Time-series dynamics are matrix dynamics with random forcing.
:::
## 5.14 Interactive HTML: root geometry and recurrence behavior
This interactive module uses the forward-root convention. It builds a second-order recurrence with complex-conjugate roots
$$
\lambda_{1,2}=re^{\pm i\omega}.
$$
Then
$$
x_t=2r\cos(\omega)x_{t-1}-r^2x_{t-2}.
$$
Move $r$ to see damping, unit-root oscillation, and explosive behavior. Move $\omega$ to change the cycle length.
<div class="interactive-card">
<div class="controls">
<label>Forward-root radius $r$
<input id="ch05_radius" type="range" min="0.40" max="1.25" step="0.01" value="0.82">
<span id="ch05_radius_value"></span>
</label>
<label>Angle $\omega/\pi$
<input id="ch05_angle" type="range" min="0.04" max="0.96" step="0.01" value="0.20">
<span id="ch05_angle_value"></span>
</label>
<label>Initial value $x_0$
<input id="ch05_x0" type="range" min="-3.0" max="3.0" step="0.1" value="1.0">
<span id="ch05_x0_value"></span>
</label>
<label>Initial value $x_1$
<input id="ch05_x1" type="range" min="-3.0" max="3.0" step="0.1" value="0.6">
<span id="ch05_x1_value"></span>
</label>
<label>Horizon
<input id="ch05_horizon" type="range" min="20" max="160" step="1" value="80">
<span id="ch05_horizon_value"></span>
</label>
</div>
<div id="ch05_status" class="small"></div>
<div id="ch05_time_plot" style="height:420px;"></div>
<div id="ch05_root_plot" style="height:420px;"></div>
</div>
<script>
(function() {
function ready(fn) {
if (document.readyState !== "loading") fn();
else document.addEventListener("DOMContentLoaded", fn);
}
ready(function() {
const radiusSlider = document.getElementById("ch05_radius");
const angleSlider = document.getElementById("ch05_angle");
const x0Slider = document.getElementById("ch05_x0");
const x1Slider = document.getElementById("ch05_x1");
const horizonSlider = document.getElementById("ch05_horizon");
const radiusValue = document.getElementById("ch05_radius_value");
const angleValue = document.getElementById("ch05_angle_value");
const x0Value = document.getElementById("ch05_x0_value");
const x1Value = document.getElementById("ch05_x1_value");
const horizonValue = document.getElementById("ch05_horizon_value");
const status = document.getElementById("ch05_status");
if (!window.Plotly) {
status.innerHTML = "Plotly is not available. Check that assets/header.html loads Plotly.js once globally.";
return;
}
function linspace(a, b, n) {
const out = [];
for (let i = 0; i < n; i++) out.push(a + (b - a) * i / (n - 1));
return out;
}
function update() {
const r = parseFloat(radiusSlider.value);
const angleFrac = parseFloat(angleSlider.value);
const omega = Math.PI * angleFrac;
const x0 = parseFloat(x0Slider.value);
const x1 = parseFloat(x1Slider.value);
const horizon = parseInt(horizonSlider.value, 10);
const phi1 = 2 * r * Math.cos(omega);
const phi2 = -r * r;
radiusValue.textContent = r.toFixed(2);
angleValue.textContent = angleFrac.toFixed(2);
x0Value.textContent = x0.toFixed(1);
x1Value.textContent = x1.toFixed(1);
horizonValue.textContent = String(horizon);
const x = new Array(horizon + 1).fill(0);
x[0] = x0;
x[1] = x1;
for (let t = 2; t <= horizon; t++) {
x[t] = phi1 * x[t - 1] + phi2 * x[t - 2];
}
const t = x.map((_, i) => i);
const period = 2 * Math.PI / omega;
const backshiftRadius = 1 / r;
let behavior = "stable damped oscillation";
if (Math.abs(r - 1) < 0.015) behavior = "approximately undamped unit-root oscillation";
if (r > 1) behavior = "explosive oscillation";
status.innerHTML =
"Recurrence: x_t = " + phi1.toFixed(3) + " x_{t-1} + (" + phi2.toFixed(3) + ") x_{t-2}. " +
"Forward-root radius r = " + r.toFixed(2) + ", backshift-root radius 1/r = " + backshiftRadius.toFixed(2) +
", approximate period = " + period.toFixed(1) + " steps. Behavior: " + behavior + ".";
Plotly.newPlot("ch05_time_plot", [
{
x: t,
y: x,
mode: "lines+markers",
name: "x_t"
},
{
x: [0, horizon],
y: [0, 0],
mode: "lines",
name: "zero",
hoverinfo: "skip"
}
], {
title: "Second-order recurrence path",
xaxis: {title: "time t"},
yaxis: {title: "x_t"},
margin: {t: 50, r: 20, b: 50, l: 60},
showlegend: false
}, {responsive: true});
const theta = linspace(0, 2 * Math.PI, 300);
const unitX = theta.map(v => Math.cos(v));
const unitY = theta.map(v => Math.sin(v));
const rootX = [r * Math.cos(omega), r * Math.cos(-omega)];
const rootY = [r * Math.sin(omega), r * Math.sin(-omega)];
const br = 1 / r;
const backX = [br * Math.cos(omega), br * Math.cos(-omega)];
const backY = [-br * Math.sin(omega), -br * Math.sin(-omega)];
Plotly.newPlot("ch05_root_plot", [
{
x: unitX,
y: unitY,
mode: "lines",
name: "unit circle",
hoverinfo: "skip"
},
{
x: rootX,
y: rootY,
mode: "markers",
marker: {size: 12},
name: "forward roots lambda"
},
{
x: backX,
y: backY,
mode: "markers",
marker: {size: 10, symbol: "x"},
name: "backshift roots z = 1/lambda"
}
], {
title: "Forward roots and reciprocal backshift roots",
xaxis: {title: "Real part", range: [-2.8, 2.8], zeroline: true, scaleanchor: "y", scaleratio: 1},
yaxis: {title: "Imaginary part", range: [-2.8, 2.8], zeroline: true},
margin: {t: 50, r: 20, b: 50, l: 60},
showlegend: true
}, {responsive: true});
}
[radiusSlider, angleSlider, x0Slider, x1Slider, horizonSlider].forEach(el => {
el.addEventListener("input", update);
});
update();
});
})();
</script>
::: {.callout-note}
## What to observe
When $r<1$, the forward roots are inside the unit circle and the recurrence path decays. In the time-series backshift convention, the reciprocal roots lie outside the unit circle, giving a causal stationary AR model. When $r>1$, the forward roots lie outside the unit circle and the recurrence path explodes.
:::
## 5.15 Python example: solve a recurrence from roots
The following example constructs an AR(2)-type recurrence from complex roots and plots the deterministic path.
```{python}
#| label: py-ch05-damped-recurrence
#| echo: true
#| message: false
#| warning: false
import numpy as np
import matplotlib.pyplot as plt
r = 0.85
omega = np.pi / 6 # period approximately 12
phi1 = 2 * r * np.cos(omega)
phi2 = -r**2
n = 80
x = np.zeros(n)
x[0] = 1.0
x[1] = 0.5
for t in range(2, n):
x[t] = phi1 * x[t-1] + phi2 * x[t-2]
print(f"phi1 = {phi1:.3f}, phi2 = {phi2:.3f}")
print(f"Approximate period = {2*np.pi/omega:.1f} time steps")
plt.figure(figsize=(8, 4))
plt.plot(x, marker="o", markersize=3)
plt.axhline(0, linewidth=1)
plt.xlabel("time")
plt.ylabel("x_t")
plt.title("Damped oscillation from complex roots")
plt.show()
```
The parameter $r$ controls the damping. Try changing it to $0.98$ and then to $1.02$.
## 5.16 Python example: impulse response of an AR(2)
Now compute the impulse response $\psi_j$ for
$$
X_t=\phi_1X_{t-1}+\phi_2X_{t-2}+W_t.
$$
The coefficients satisfy
$$
\psi_0=1,
\qquad
\psi_1=\phi_1,
\qquad
\psi_j=\phi_1\psi_{j-1}+\phi_2\psi_{j-2}.
$$
```{python}
#| label: py-ch05-impulse-response
#| echo: true
#| message: false
#| warning: false
import numpy as np
import matplotlib.pyplot as plt
phi1 = 1.2
phi2 = -0.7
horizon = 50
psi = np.zeros(horizon + 1)
psi[0] = 1.0
psi[1] = phi1
for j in range(2, horizon + 1):
psi[j] = phi1 * psi[j-1] + phi2 * psi[j-2]
plt.figure(figsize=(8, 4))
plt.stem(range(horizon + 1), psi)
plt.axhline(0, linewidth=1)
plt.xlabel("lag j")
plt.ylabel("psi_j")
plt.title("Impulse-response coefficients for AR(2)")
plt.show()
```
The impulse response is exactly the effect of one unit shock at time $t$ on future values $X_t,X_{t+1},X_{t+2},\ldots$.
## 5.17 Python example: companion matrix and eigenvalues
The AR(2) model can be represented by the companion matrix
$$
A=\begin{bmatrix}
\phi_1 & \phi_2\\
1 & 0
\end{bmatrix}.
$$
Its eigenvalues are the forward characteristic roots.
```{python}
#| label: py-ch05-companion-matrix
#| echo: true
#| message: false
#| warning: false
import numpy as np
phi1 = 1.2
phi2 = -0.7
A = np.array([[phi1, phi2],
[1.0, 0.0]])
eigvals = np.linalg.eigvals(A)
print("Companion matrix:")
print(A)
print("Eigenvalues:", eigvals)
print("Spectral radius:", np.max(np.abs(eigvals)))
print("Stable forward dynamics?", np.max(np.abs(eigvals)) < 1)
# Backshift polynomial roots are reciprocals of forward roots.
z_roots = 1 / eigvals
print("Backshift roots:", z_roots)
print("Causal AR condition |z| > 1?", np.all(np.abs(z_roots) > 1))
```
This example is useful because it connects time-series stability to a linear algebra concept that students already know: eigenvalues.
## 5.18 Python example: simulate stable, near-unit, and explosive AR(1)
A first-order model already shows the three most important regimes.
```{python}
#| label: py-ch05-ar1-regimes
#| echo: true
#| message: false
#| warning: false
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(123)
n = 160
phis = [0.6, 0.98, 1.02]
labels = ["stable phi=0.6", "near unit phi=0.98", "explosive phi=1.02"]
plt.figure(figsize=(9, 5))
for phi, label in zip(phis, labels):
w = rng.normal(0, 1, n)
x = np.zeros(n)
for t in range(1, n):
x[t] = phi * x[t-1] + w[t]
plt.plot(x, label=label)
plt.axhline(0, linewidth=1)
plt.xlabel("time")
plt.ylabel("X_t")
plt.title("AR(1) dynamic regimes")
plt.legend()
plt.show()
```
Even if $\phi=1.02$ looks only mildly larger than $1$, the long-run behavior changes dramatically.
## 5.19 AI-assisted study: checking root conventions
AI tools are helpful for algebraic manipulation, but root conventions in time series are a common source of incorrect answers. Use AI as a checker, not as an authority.
::: {.callout-tip}
## AI prompt: root convention audit
I am studying the AR(2) model $X_t=\phi_1X_{t-1}+\phi_2X_{t-2}+W_t$. Explain the difference between roots of the forward characteristic equation $\lambda^2-\phi_1\lambda-\phi_2=0$ and roots of the backshift polynomial $1-\phi_1z-\phi_2z^2=0$. Verify that $\lambda=1/z$, and explain which root condition corresponds to causal stationarity.
:::
::: {.callout-tip}
## AI prompt: recurrence solver
Solve the recurrence $x_t=1.2x_{t-1}-0.7x_{t-2}$ with $x_0=1$ and $x_1=0.5$. First compute the characteristic roots. Then write the solution in real-valued damped-oscillation form. Finally, give a short Python snippet that verifies the formula numerically.
:::
::: {.callout-warning}
## What to verify manually
When an AI assistant gives an answer, check these four items yourself:
1. Did it use the forward-root or backshift-root convention?
2. Did it reverse the stability condition?
3. Did it handle complex roots as conjugate pairs?
4. Did it confuse deterministic recurrence behavior with stochastic stationarity?
:::
## 5.20 Common mistakes
### Mistake 1: Saying roots inside the unit circle are always stable
This depends on which roots you mean. Forward roots $\lambda$ must be inside the unit circle. Backshift roots $z$ must be outside the unit circle.
### Mistake 2: Treating oscillation as seasonality
A complex-root AR(2) process can oscillate, but the oscillation is stochastic and damped. Deterministic seasonality has a more regular periodic component.
### Mistake 3: Ignoring roots close to one
Roots close to the unit circle produce slow decay. A model can be technically stationary but practically difficult to distinguish from a nonstationary process in finite samples.
### Mistake 4: Forgetting initial conditions
The constants in the homogeneous solution are determined by initial conditions. In stochastic stationary modeling, the influence of initial conditions must decay.
### Mistake 5: Confusing impulse response and sample path
The impulse response is deterministic once model parameters are fixed. A sample path is random because it includes many shocks.
## 5.21 Mini project: dynamic signatures of AR(2) models
Choose four AR(2) models:
1. two positive real forward roots inside the unit circle;
2. one positive and one negative real forward root;
3. complex forward roots with radius $0.75$;
4. complex forward roots with radius $0.98$.
For each model:
1. compute $\phi_1$ and $\phi_2$;
2. simulate a sample path;
3. plot the impulse response;
4. plot the sample ACF;
5. compute the companion-matrix eigenvalues;
6. explain the observed behavior in terms of roots.
Your report should include one paragraph answering:
> Which model would be hardest to distinguish from a nonstationary process in a short sample, and why?
## 5.22 Exercises
### Conceptual exercises
1. Explain why the AR(1) model $X_t=0.95X_{t-1}+W_t$ is stationary but highly persistent.
2. Explain why the random walk $X_t=X_{t-1}+W_t$ is not stationary.
3. Give an example of AR(2) forward roots that produce damped oscillation with approximate period $8$.
4. Explain the relationship between the roots of $\lambda^2-\phi_1\lambda-\phi_2=0$ and the roots of $1-\phi_1z-\phi_2z^2=0$.
5. Why can an AR(2) model have an ACF that oscillates?
### Mathematical exercises
6. Solve the recurrence
$$
x_t=0.7x_{t-1}+0.1x_{t-2}
$$
with $x_0=1$ and $x_1=0$.
7. Suppose an AR(2) model has forward roots $0.8$ and $-0.3$. Find $\phi_1$ and $\phi_2$.
8. Suppose an AR(2) model has forward roots $0.9e^{\pm i\pi/4}$. Find $\phi_1$ and $\phi_2$.
9. Show that if $x_t=\phi x_{t-1}$ and $|\phi|<1$, then $x_t\to0$.
10. Show that the AR(1) autocovariance satisfies
$$
\gamma(h)=\phi\gamma(h-1),
$$
and therefore $\rho(h)=\phi^h$ for $h\ge0$.
### Computational exercises
11. Write a Python function `ar2_from_forward_roots(r, omega)` that returns $\phi_1$ and $\phi_2$ for complex roots $re^{\pm i\omega}$.
12. Write a Python function that computes the first $m$ impulse-response coefficients of an AR($p$) model.
13. Simulate AR(2) models with the same root angle but different root radii. Compare their sample ACFs.
14. Use the companion matrix to check whether the AR(3) model
$$
X_t=0.5X_{t-1}+0.2X_{t-2}-0.1X_{t-3}+W_t
$$
has stable forward dynamics.
15. Generate an explosive AR(1) path with $\phi=1.05$. Then difference it and comment on whether the differenced series appears stationary.
## 5.23 Chapter checklist
By the end of this chapter, you should be able to complete the following checklist.
- [ ] I can write an AR model as a linear difference equation.
- [ ] I can solve a first-order homogeneous recurrence.
- [ ] I can derive the characteristic equation of an AR(2) recurrence.
- [ ] I can explain the difference between forward roots and backshift roots.
- [ ] I can identify stable, unit-root, and explosive behavior from roots.
- [ ] I can explain why complex roots create damped oscillations.
- [ ] I can write the repeated-root solution form.
- [ ] I can compute AR(2) impulse-response coefficients recursively.
- [ ] I can build a companion matrix for an AR($p$) model.
- [ ] I can connect eigenvalues of the companion matrix to AR stability.
- [ ] I can explain why the ACF of an AR model satisfies a difference equation.
- [ ] I can use AI to check my algebra without accepting its root convention blindly.
## 5.24 Summary
Difference equations provide the mathematical language for time-series dynamics. In AR models, the same recurrence controls deterministic paths, impulse responses, and autocovariance decay. Real roots produce monotone or alternating decay. Complex roots produce damped oscillations. Repeated roots create polynomial-exponential behavior. The companion matrix connects the theory to linear algebra: stability is an eigenvalue condition.
The next chapter uses these ideas for forecasting. Once we understand how shocks propagate through a model, we can quantify how uncertainty grows with the forecast horizon.
## Key formulas
First-order recurrence:
$$
x_t=\phi^t x_0.
$$
AR(2) forward characteristic equation:
$$
\lambda^2-\phi_1\lambda-\phi_2=0.
$$
Backshift polynomial:
$$
\phi(z)=1-\phi_1z-\phi_2z^2.
$$
Root relationship:
$$
\lambda=\frac{1}{z}.
$$
Complex-root AR(2) coefficients:
$$
\lambda_{1,2}=re^{\pm i\omega}
\quad\Longrightarrow\quad
\phi_1=2r\cos(\omega),
\qquad
\phi_2=-r^2.
$$
Damped oscillation solution:
$$
x_t=r^t\{A\cos(\omega t)+B\sin(\omega t)\}.
$$
Repeated-root solution:
$$
x_t=(c_0+c_1t+\cdots+c_{m-1}t^{m-1})\lambda^t.
$$
AR($p$) companion matrix:
$$
A=
\begin{bmatrix}
\phi_1 & \phi_2 & \cdots & \phi_{p-1} & \phi_p\\
1 & 0 & \cdots & 0 & 0\\
0 & 1 & \cdots & 0 & 0\\
\vdots & \vdots & \ddots & \vdots & \vdots\\
0 & 0 & \cdots & 1 & 0
\end{bmatrix}.
$$
Stability in forward-root convention:
$$
\rho(A)<1.
$$
Causal AR condition in backshift-root convention:
$$
\phi(z)=0 \quad\Longrightarrow\quad |z|>1.
$$