Module contents
Lesson 11 of 31Core 115 min

AR, MA and ARMA models

Linear time-series models: linear processes as white-noise filters, autoregressive, moving-average and ARMA models. Study causality and invertibility through polynomial roots, ACF and PACF signatures, Yule-Walker estimation and the Durbin-Levinson recursion, which gives both the PACF and the best linear predictor.

After this lesson you can

  • Calculate theoretical ACF and PACF for AR(1), AR(2), MA(1) and ARMA(1,1) and recognize their signatures in data.
  • Determine causality and invertibility from polynomial roots and obtain the MA(∞) representation.
  • Estimate an AR(p) using Yule-Walker and least squares and compare their properties.
  • Implement Durbin-Levinson and use it to calculate PACF and linear forecasts with their errors.
  • Explain the identifiability problem when φ(z) and θ(z) share roots.

Before you start

The past as a filter

A value today can retain an old shock’s effect or share a recent innovation with yesterday’s value. An autoregressive model describes the first kind of memory through a recurrence; a moving average mixes present and past innovations. These names describe mechanisms different from the centered moving averages used to decompose a series.

In an AR(2), move the inverse roots and observe how the path and autocorrelation change. Complex conjugate roots can produce damped oscillations without a permanent deterministic cycle.

InteractiveAR(2) roots and memory

In Xₜ=φ₁Xₜ₋₁+φ₂Xₜ₋₂+εₜ, with independent normal innovations of variance one, points r₁ and r₂ satisfy 1−φ₁z−φ₂z²=(1−r₁z)(1−r₂z). Thus φ₁=r₁+r₂ and φ₂=−r₁r₂. Points represent inverses of roots in z; a zero inverse corresponds to a root at infinity.

Inverse-root plane

Real part horizontal; imaginary part vertical

Stability triangle in (φ₁, φ₂)

φ₁ horizontal; φ₂ vertical. The boundary is excluded.

One simulated path

Displayed path time

Theoretical ACF of causal model

Lag h
  • First inverse or upper conjugate
  • Second inverse
  • AR(2) coefficients

Causal stability requires both moduli strictly less than one; equivalently, the interior of φ₂>−1, φ₁+φ₂<1 and φ₂−φ₁<1. For nonreal conjugates, angle θ determines phase period 2π/θ; it may be noninteger and describes root oscillation, not a promise of regular cycles in a noisy sample.

Stable theoretical ACF uses ρ(1)=φ₁/(1−φ₂) and ρ(h)=φ₁ρ(h−1)+φ₂ρ(h−2). The path starts from two zeroes: within the stable region the first 300 steps are discarded, an approximation that may be insufficient near the boundary; outside it the transient from zero is shown without burn-in. A finite realization can grow greatly without increasing at each step.

Inverse roots
0.90
0.60
φ₁1.486
φ₂−0.810
Maximum inverse modulus0.900
Causal regimeStable
Root phase period10.47 steps
Seed2611
Relate inverse roots to coefficients, path and autocorrelation. Outside the causal region no stationary ACF is shown.

Linear processes and the lag operator

Let εt\varepsilon_t be centered white noise with variance σ2>0\sigma^2>0. A causal linear process is written

Xt=μ+∑j=0∞ψjεt−j,∑j≥0ψj2<∞.X_t=\mu+\sum_{j=0}^\infty\psi_j\varepsilon_{t-j}, \qquad \sum_{j\ge0}\psi_j^2<\infty.

The sum converges in L2L^2 by orthogonality of innovations. Its autocovariance is

γ(h)=σ2∑j=0∞ψjψj+∣h∣.\gamma(h)=\sigma^2\sum_{j=0}^\infty\psi_j\psi_{j+|h|}.

The result depends on weak stationarity and convergence, not on Gaussian innovations. If coefficients are absolutely summable, the filter is also stable in that stronger sense. Relation γ(−h)=γ(h)\gamma(-h)=\gamma(h) recovers negative lags.

The lag operator BB acts as BXt=Xt−1BX_t=X_{t-1}. An autoregressive AR(pp) model and a moving-average MA(qq) model use the convention

ϕ(B)(Xt−μ)=θ(B)εt,ϕ(z)=1−∑j=1pϕjzj,θ(z)=1+∑j=1qθjzj.\phi(B)(X_t-\mu)=\theta(B)\varepsilon_t,\quad \phi(z)=1-\sum_{j=1}^p\phi_jz^j,\quad \theta(z)=1+\sum_{j=1}^q\theta_jz^j.

If q=0q=0 it is AR, if p=0p=0 it is MA, and when both can be positive it is an ARMA(p,qp,q). The constant of an AR regression with mean μ\mu is (1−∑jϕj)μ(1-\sum_j\phi_j)\mu, not necessarily μ\mu. The statsmodels library takes AR polynomial coefficients, with signs opposite to the recurrence, and initial coefficient 1.

Roots, causality and invertibility

Causality and invertibility are read from polynomials without common factors, reduced to their actual degree. If no root of ϕ(z)\phi(z) lies in the closed unit disk, the ARMA admits a stable causal representation ψ(B)=θ(B)/ϕ(B)\psi(B)=\theta(B)/\phi(B). If no root of θ(z)\theta(z) lies in that disk, innovations can be recovered through a stable causal filter of centered observations: εt=ϕ(B)(Xt−μ)/θ(B)\varepsilon_t=\phi(B)(X_t-\mu)/\theta(B).

The polynomial roots are outside the circle; their inverses are inside. The boundary requires special treatment: absolute stability does not follow. A stationary noncausal representation may exist with AR roots outside the causal region if it depends on future innovations; here causal refers to filter direction, not experimental causality.

If ϕ\phi and θ\theta share a factor, it cancels in the reduced representation and original parameters are not identifiable from the process law. For example, (1−aB)Xt=(1−aB)εt(1-aB)X_t=(1-aB)\varepsilon_t contains exact cancellation; under the corresponding stable causal solution, Xt=εtX_t=\varepsilon_t for any ∣a∣<1|a|<1. Nearly shared roots give a weak signal and can make estimation unstable even when not identical.

AR(1), AR(2) y MA(1)

For Xt=ϕXt−1+εtX_t=\phi X_{t-1}+\varepsilon_t with ∣ϕ∣<1|\phi|<1, the causal solution is Xt=∑j≥0ϕjεt−jX_t=\sum_{j\ge0}\phi^j\varepsilon_{t-j}. Thus,

γ(0)=σ21−ϕ2,ρ(h)=ϕ∣h∣.\gamma(0)=\frac{\sigma^2}{1-\phi^2},\qquad \rho(h)=\phi^{|h|}.

With ϕ<0\phi<0 signs alternate; with ϕ>0\phi>0 the ACF decays without alternating. For a causal AR(2), the Yule-Walker equations give

ρ(1)=ϕ11−ϕ2,ρ(2)=ϕ1ρ(1)+ϕ2,ρ(h)=ϕ1ρ(h−1)+ϕ2ρ(h−2)(h≥2).\rho(1)=\frac{\phi_1}{1-\phi_2},\quad \rho(2)=\phi_1\rho(1)+\phi_2,\quad \rho(h)=\phi_1\rho(h-1)+\phi_2\rho(h-2)\quad(h\ge2).

The strict causal region is ϕ2>−1\phi_2>-1, ϕ1+ϕ2<1\phi_1+\phi_2<1 and ϕ2−ϕ1<1\phi_2-\phi_1<1. If inverse roots are re±iωre^{\pm i\omega} with 0<r<10<r<1 and 0<ω<π0<\omega<\pi, the transient response oscillates with angular period 2π/ω2\pi/\omega and decreasing envelope. This does not require the spectral maximum or period estimated from a finite path to equal that value exactly.

For Xt=εt+θεt−1X_t=\varepsilon_t+\theta\varepsilon_{t-1}, γ(0)=σ2(1+θ2)\gamma(0)=\sigma^2(1+\theta^2), γ(1)=σ2θ\gamma(1)=\sigma^2\theta and γ(h)=0\gamma(h)=0 for ∣h∣>1|h|>1. Therefore ρ(1)=θ/(1+θ2)\rho(1)=\theta/(1+\theta^2). The pairs θ\theta and 1/θ1/\theta can produce the same autocovariance if innovation variance is adjusted: invertibility chooses ∣θ∣<1|\theta|<1 to obtain a canonical representation. Matching autocovariances do not imply equal finite-dimensional distributions without additional assumptions such as Gaussianity.

The mixed ARMA(1,1) case

With Xt=ϕXt−1+εt+θεt−1X_t=\phi X_{t-1}+\varepsilon_t+\theta\varepsilon_{t-1} and ∣ϕ∣<1|\phi|<1,

ψ0=1,ψj=(ϕ+θ)ϕj−1(j≥1),\psi_0=1,\qquad \psi_j=(\phi+\theta)\phi^{j-1}\quad(j\ge1), ρ(1)=(ϕ+θ)(1+ϕθ)1+2ϕθ+θ2,ρ(h)=ϕh−1ρ(1)(h≥1).\rho(1)=\frac{(\phi+\theta)(1+\phi\theta)} {1+2\phi\theta+\theta^2},\qquad \rho(h)=\phi^{h-1}\rho(1)\quad(h\ge1).

The formula follows by summing products of coefficients ψj\psi_j. Cancellation θ=−ϕ\theta=-\phi leaves white noise: writing two parameters does not create two identifiable effects. Invertibility of this representation additionally requires ∣θ∣<1|\theta|<1. In general, neither ACF nor PACF of a mixed model has a clean cutoff.

Partial autocorrelation at kk is the final coefficient of the best linear predictor of XtX_t from Xt−1,…,Xt−kX_{t-1},\ldots,X_{t-k}, or equivalently the correlation of endpoints after projection onto intermediate lags, when residual variances are positive. In a causal AR(pp) with effective order pp, PACF vanishes after pp; in an MA(qq), ACF vanishes after qq. These cutoffs are theoretical and a finite sample may produce bars beyond them.

For MA(1), if ∣θ∣≠1|\theta|\ne1, PACF at k≥1k\ge1 is

αk=(−1)k−1θk(1−θ2)1−θ2k+2;\alpha_k=\frac{(-1)^{k-1}\theta^k(1-\theta^2)} {1-\theta^{2k+2}};

the expression has a limit when ∣θ∣=1|\theta|=1. For AR(1), PACF is ϕ\phi at the first lag and zero afterward; for AR(2) it is α1=ϕ1/(1−ϕ2)\alpha_1=\phi_1/(1-\phi_2) and α2=ϕ2\alpha_2=\phi_2, and vanishes afterward. For ARMA(1,1), apply the next section’s recursion to its ACF: it yields each theoretical PACF without assuming a cutoff. Near cancellations and short samples can make distinct signatures look similar.

InteractiveRecognize signatures in finite data
  • Sample ACF
  • Sample PACF
  • Reference ±1.96/√n

Sample ACF

Sample PACF

Horizontal axis: lags 1 through 12. Dashed lines are an approximate white-noise reference; they are not general ARMA confidence bands and do not correct for examining multiple lags.

Each round reproducibly chooses white noise, AR(1), AR(2), MA(1), MA(2), or ARMA(1,1), with variable coefficients and inverse roots of modulus less than one. Innovations are independent normal; the first 200 steps are discarded. Changing n preserves the beginning of the same realization.

The ACF centers the sample by its mean and uses divisor n for all autocovariances. PACF comes from Durbin–Levinson applied to that ACF. Frequency counts only your revealed answers with the same n: it depends on your decisions and does not by itself estimate a universal confusion probability. A sample may suggest cutoffs that do not exist or hide real ones.

200
1
1
ResultHidden model
True orders (p, q)Hidden
Decisions recorded with n = 2000
Error fraction for this nNo decisions
Try to identify the hidden model from sample autocorrelations. Seed and parameters come from explicit simulations; the bars do not guarantee identification.

Linear prediction and Durbin-Levinson

Orthogonal projection onto Xt−1,…,Xt−kX_{t-1},\ldots,X_{t-k} leads to the Yule-Walker equations Γkϕk=γk\Gamma_k\boldsymbol\phi_k=\boldsymbol\gamma_k, with Γk=[γ(i−j)]i,j=1k\Gamma_k=[\gamma(i-j)]_{i,j=1}^k and γk=(γ(1),…,γ(k))T\boldsymbol\gamma_k=(\gamma(1),\ldots,\gamma(k))^\mathsf T. For unknown mean, center the series; sample covariance with common divisor nn keeps the matrix positive semidefinite. The solution is unique if Γk\Gamma_k is positive definite.

The Durbin-Levinson recursion extends the projection one lag at a time. With v0=γ(0)v_0=\gamma(0) and vk−1>0v_{k-1}>0,

αk=γ(k)−∑j=1k−1ϕk−1,jγ(k−j)vk−1,ϕk,j=ϕk−1,j−αkϕk−1,k−j(1≤j<k),ϕk,k=αk,vk=vk−1(1−αk2).\begin{aligned} \alpha_k&=\frac{\gamma(k)-\sum_{j=1}^{k-1}\phi_{k-1,j}\gamma(k-j)}{v_{k-1}},\\ \phi_{k,j}&=\phi_{k-1,j}-\alpha_k\phi_{k-1,k-j}\quad(1\le j<k),\\ \phi_{k,k}&=\alpha_k,\qquad v_k=v_{k-1}(1-\alpha_k^2). \end{aligned}

αk\alpha_k is PACF, ϕk,j\phi_{k,j} are linear predictor coefficients and vkv_k its error variance. The reduction follows by projecting onto the new residual orthogonal to the previous space. If a covariance matrix is singular, division requires handling the degenerate case. This is optimal linear prediction; it equals conditional expectation under joint Gaussianity, but not necessarily for every non-Gaussian process.

InteractiveEach lag adds a projection
order 1 / 6

AR(2): Xₜ = 0.8Xₜ₋₁ − 0.35Xₜ₋₂ + εₜ. Autoregressive roots lie outside the unit circle; a stationary causal solution exists. In both cases εₜ is white noise with mean zero and variance 1.

System Γₖ φₖ = (γ₁, …, γₖ)ᵀ: new row and column highlighted; rounded values

1.756|1.041

Predictor coefficients, in lag order:

φ1,1 = 0.5926

Reflection coefficients obtained through current order

Lag k
  • Previous orders
  • Current order

κₖ = (γₖ − Σⱼ φₖ₋₁,ⱼ γₖ₋ⱼ) / vₖ₋₁; the numerator at this step is 1.0408. For j < k, φₖ,ⱼ = φₖ₋₁,ⱼ − κₖφₖ₋₁,ₖ₋ⱼ, and φₖ,ₖ = κₖ. Variance updates as vₖ = vₖ₋₁(1 − κₖ²), with v₀ = γ₀. The system is also solved by partial-pivot elimination; the difference compares both vectors before rounding.

This AR(2)’s PACF vanishes after lag two; the selected ARMA has no such cutoff. Bars are population values, not sample estimates. The recursion requires positive error variances: a singular or nearly singular covariance matrix would stop it rather than divide by zero.

Stationary process
Order k1
Reflection κₖ = PACF(k)0.5926
Previous error vₖ₋₁1.7564
New error vₖ1.1396
Reduction versus v₀35.1 %
Maximum difference from Toeplitz0.00e+0
Step through the Toeplitz system and observe updates to coefficients, PACF and error variance.

Estimation is not identification by looking at bars

Yule-Walker replaces theoretical autocovariances with estimates and solves the Toeplitz system. Conditional least squares fits each observation to available lags, discarding the prefix and estimating an intercept when appropriate. The methods differ in boundaries, normalization and treatment of the mean; they need not agree in finite samples.

For a fixed causal AR(1), with iid finite-variance innovations and usual regularity conditions, the least-squares estimator is consistent and its first-order asymptotic variance is (1−ϕ2)/n(1-\phi^2)/n. That approximation does not automatically describe short samples or parameters approaching one with nn well. When ϕ\phi is close to one, burn-in needed to simulate stationarity grows and finite-sample biases can be significant.

Lab: filters, projections and estimation

In the following cells innovations are iid normal, seeds are fixed and burn-in is stated. The theoretical representation is truncated to calculate a controllable approximation: compare it with statsmodels arma_acf, which takes polynomials with initial coefficient.

[ ]ARMA weights and simulationBrowser
import numpy as np
from statsmodels.tsa.arima_process import arma_acf, ArmaProcess

def psi_arma(phi, theta, cantidad):
    phi, theta = np.asarray(phi), np.asarray(theta)
    psi = np.zeros(cantidad)
    psi[0] = 1.
    for j in range(1, cantidad):
        psi[j] = (theta[j-1] if j <= len(theta) else 0.)
        for i in range(1, min(j, len(phi))+1):
            psi[j] += phi[i-1]*psi[j-i]
    return psi

def acf_desde_psi(psi, maxlag):
    g = np.array([psi[:len(psi)-h] @ psi[h:] for h in range(maxlag+1)])
    return g/g[0]

def simular_arma(phi, theta, n, burn, rng):
    phi, theta = np.asarray(phi), np.asarray(theta)
    p, q = len(phi), len(theta)
    e = rng.normal(size=n+burn)
    x = np.zeros(n+burn)
    for t in range(len(x)):
        x[t] = e[t]
        for i in range(1, min(p,t)+1):
            x[t] += phi[i-1]*x[t-i]
        for j in range(1, min(q,t)+1):
            x[t] += theta[j-1]*e[t-j]
    return x[burn:]

phi, theta = [.7], [.4]
psi = psi_arma(phi, theta, 300)
ref_acf = arma_acf(np.r_[1., -np.array(phi)], np.r_[1., theta], lags=11)
print("primeros pesos:", np.round(psi[:6], 5))
print("máximo error ACF truncada:", np.max(abs(acf_desde_psi(psi, 10)-ref_acf)))
rng = np.random.default_rng(2611)
serie = simular_arma(phi, theta, 2000, 300, rng)
modelo = ArmaProcess(np.r_[1., -np.array(phi)], np.r_[1., theta])
print("proceso causal e invertible:", modelo.isstationary, modelo.isinvertible)
print("media y varianza de una trayectoria:", serie.mean(), serie.var())
r1, r2 = np.random.default_rng(12), np.random.default_rng(12)
propia = simular_arma(phi, theta, 300, 100, r1)
referencia = modelo.generate_sample(nsample=300, burnin=100, distrvs=r2.standard_normal)
print("error máximo de simulación con innovaciones iguales:", np.max(abs(propia-referencia)))

Burn-in approximates stationarity; a fixed length does not guarantee it for every root near one. In this example the power of 0.70.7 falls quickly; if you change the model, reconsider length and truncation error.

[ ]Durbin-Levinson and direct solutionBrowser
from scipy.linalg import toeplitz
from statsmodels.tsa.stattools import levinson_durbin

def durbin(gamma):
    gamma = np.asarray(gamma, dtype=float)
    if len(gamma) < 1 or gamma[0] <= 0:
        raise ValueError("covarianza inicial inválida")
    coef = np.empty(0)
    pacf = [1.]
    errores = [gamma[0]]
    for k in range(1, len(gamma)):
        reflejo = (gamma[k]-np.dot(coef, gamma[1:k][::-1]))/errores[-1]
        nuevo = np.r_[coef-reflejo*coef[::-1], reflejo]
        error = errores[-1]*(1-reflejo**2)
        if error <= 0:
            raise ValueError("matriz no definida positiva")
        coef = nuevo
        pacf.append(reflejo)
        errores.append(error)
    return coef, np.array(pacf), np.array(errores)

gamma = acf_desde_psi(psi, 10)
coef, pacf, errores = durbin(gamma)
directo = np.linalg.solve(toeplitz(gamma[:10]), gamma[1:11])
ref_v, ref_ar, ref_pacf, _, _ = levinson_durbin(gamma, nlags=10, isacov=True)
print("error respecto al sistema directo:", np.max(abs(coef-directo)))
print("error PACF frente a statsmodels:", np.max(abs(pacf-ref_pacf)))
print("varianza final propia y de referencia:", errores[-1], ref_v)
print("PACF teórica, primeros 4 retardos:", np.round(pacf[1:5], 5))
[ ]Yule-Walker versus least squaresBrowser
def acov_muestral(x, p):
    z = x-x.mean()
    return np.array([z[:len(z)-h] @ z[h:]/len(z) for h in range(p+1)])

def yw(x, p):
    g = acov_muestral(np.asarray(x), p)
    return np.linalg.solve(toeplitz(g[:p]), g[1:])

def ols_ar(x, p):
    x = np.asarray(x)
    matriz = np.column_stack([np.ones(len(x)-p)] +
                             [x[p-j:len(x)-j] for j in range(1,p+1)])
    return np.linalg.lstsq(matriz, x[p:], rcond=None)[0]

from statsmodels.regression.linear_model import yule_walker
coef_yw = yw(serie, 2)
coef_ols = ols_ar(serie, 2)
coef_ref, _ = yule_walker(serie, order=2, method="mle", demean=True)
print("YW propio y statsmodels:", coef_yw, coef_ref)
print("OLS con intercepto:", coef_ols)

The following simulation repeats an AR(1) with a fixed coefficient near one. Each replication has new innovations and 500 burn-in steps; the comparison concerns the selected generator and sizes, not a universal bias law. Monte Carlo error decreases with more replications.

[ ]Finite-sample bias near unityBrowser
rng = np.random.default_rng(64)
reps, phi = 600, .95
for n in (80, 500):
    x = np.zeros(reps)
    trayectoria = np.empty((reps, n))
    for t in range(500+n):
        x = phi*x+rng.normal(size=reps)
        if t >= 500:
            trayectoria[:, t-500] = x
    centrada = trayectoria-trayectoria.mean(axis=1, keepdims=True)
    yw1 = np.sum(centrada[:,:-1]*centrada[:,1:], axis=1)/np.sum(centrada**2, axis=1)
    anterior, actual = trayectoria[:,:-1], trayectoria[:,1:]
    anterior = anterior-anterior.mean(axis=1, keepdims=True)
    actual = actual-actual.mean(axis=1, keepdims=True)
    ols1 = np.sum(anterior*actual, axis=1)/np.sum(anterior**2, axis=1)
    print("n, media YW, media OLS, sesgo YW, desviación YW:",
          n, yw1.mean(), ols1.mean(), yw1.mean()-phi, yw1.std(ddof=1))

Exercises

ProofA shock leaves a trace
Prove: For |φ|<1 and centered white noise of variance σ², prove the causal AR(1) representation and calculate γ(h).
0
Justify convergence in L² before interchanging sums and covariances.

Step 1 of 3. Why do partial sums of Σφʲεₜ₋ⱼ converge in L²?

NumericLag two of an ARMA
For Xₜ=0.7 Xₜ₋₁+εₜ+0.4 εₜ₋₁ with positive-variance white noise, calculate theoretical autocorrelation at lag 2.
QuizRoots of both polynomials
With polynomials φ(z)=1−0.6z and θ(z)=1+1.4z sharing no factors, what property does the model have?
CodeRecursion and predictor
Implement durbin_levinson(gamma): return (final coefficients, PACF including lag zero, error variances from v₀). Require γ(0)>0 and positive error variances. Also implement predecir(historia, media, coef): historia is ordered from oldest to newest and must contain at least as many values as coefficients; return the linear forecast of the next observation centered by media.
import numpy as np

def durbin_levinson(gamma):
  pass

def predecir(historia, media, coef):
  pass
Shift+Enter to run
ProofTwo MA(1) models, one autocovariance
Prove: For θ≠0, compare Xₜ=εₜ+θεₜ₋₁ with another MA(1) with parameter 1/θ. What innovation variance must the second have to match autocovariance? Which representation is invertible if |θ|>1?
0
First equate covariance at lag 1.

Step 1 of 3. If the first noise has variance σ², what must the second variance be?

Key idea

An ARMA is an innovation filter. Roots determine when it can be expressed causally and noise recovered; Yule-Walker and Durbin-Levinson turn its autocovariance into linear predictions and error variances.