32. AR(1) Processes#

32.1. Overview#

In this lecture we are going to study a very simple class of stochastic models called AR(1) processes.

These simple models are used again and again in economic research to represent the dynamics of series such as

  • labor income

  • dividends

  • productivity, etc.

We are going to study AR(1) processes partly because they are useful and partly because they help us understand important concepts.

Let’s start with some imports:

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (11, 5)  #set default figure size

32.2. The AR(1) model#

The AR(1) model (autoregressive model of order 1) takes the form

(32.1)#Xt+1=aXt+b+cWt+1

where a,b,c are scalar-valued parameters

(Equation (32.1) is sometimes called a stochastic difference equation.)

Example 32.1

For example, Xt might be

  • the log of labor income for a given household, or

  • the log of money demand in a given economy.

In either case, (32.1) shows that the current value evolves as a linear function of the previous value and an IID shock Wt+1.

(We use t+1 for the subscript of Wt+1 because this random variable is not observed at time t.)

The specification (32.1) generates a time series {Xt} as soon as we specify an initial condition X0.

To make things even simpler, we will assume that

  • the process {Wt} is IID and standard normal,

  • the initial condition X0 is drawn from the normal distribution N(μ0,v0) and

  • the initial condition X0 is independent of {Wt}.

32.2.1. Moving average representation#

Iterating backwards from time t, we obtain

Xt=aXt1+b+cWt=a2Xt2+ab+acWt1+b+cWt=a3Xt3+a2b+a2cWt2+b+cWt=

If we work all the way back to time zero, we get

(32.2)#Xt=atX0+bj=0t1aj+cj=0t1ajWtj

Equation (32.2) shows that Xt is a well defined random variable, the value of which depends on

  • the parameters,

  • the initial condition X0 and

  • the shocks W1,Wt from time t=1 to the present.

Throughout, the symbol ψt will be used to refer to the density of this random variable Xt.

32.2.2. Distribution dynamics#

One of the nice things about this model is that it’s so easy to trace out the sequence of distributions {ψt} corresponding to the time series {Xt}.

To see this, we first note that Xt is normally distributed for each t.

This is immediate from (32.2), since linear combinations of independent normal random variables are normal.

Given that Xt is normally distributed, we will know the full distribution ψt if we can pin down its first two moments.

Let μt and vt denote the mean and variance of Xt respectively.

We can pin down these values from (32.2) or we can use the following recursive expressions:

(32.3)#μt+1=aμt+bandvt+1=a2vt+c2

These expressions are obtained from (32.1) by taking, respectively, the expectation and variance of both sides of the equality.

In calculating the second expression, we are using the fact that Xt and Wt+1 are independent.

(This follows from our assumptions and (32.2).)

Given the dynamics in (32.2) and initial conditions μ0,v0, we obtain μt,vt and hence

ψt=N(μt,vt)

The following code uses these facts to track the sequence of marginal distributions {ψt}.

The parameters are

a, b, c = 0.9, 0.1, 0.5

mu, v = -3.0, 0.6  # initial conditions mu_0, v_0

Here’s the sequence of distributions:

from scipy.stats import norm

sim_length = 10
grid = np.linspace(-5, 7, 120)

fig, ax = plt.subplots()

for t in range(sim_length):
    mu = a * mu + b
    v = a**2 * v + c**2
    ax.plot(grid, norm.pdf(grid, loc=mu, scale=np.sqrt(v)),
            label=f"$\psi_{t}$",
            alpha=0.7)

ax.legend(bbox_to_anchor=[1.05,1],loc=2,borderaxespad=1)

plt.show()
<>:12: SyntaxWarning: invalid escape sequence '\p'
<>:12: SyntaxWarning: invalid escape sequence '\p'
/tmp/ipykernel_5770/1737174689.py:12: SyntaxWarning: invalid escape sequence '\p'
  label=f"$\psi_{t}$",
_images/8db60a2b124d2473ca0d9b88fef705a33356c88304fdfcaad3c1a55309459aa7.png

32.3. Stationarity and asymptotic stability#

When we use models to study the real world, it is generally preferable that our models have clear, sharp predictions.

For dynamic problems, sharp predictions are related to stability.

For example, if a dynamic model predicts that inflation always converges to some kind of steady state, then the model gives a sharp prediction.

(The prediction might be wrong, but even this is helpful, because we can judge the quality of the model.)

Notice that, in the figure above, the sequence {ψt} seems to be converging to a limiting distribution, suggesting some kind of stability.

This is even clearer if we project forward further into the future:

def plot_density_seq(ax, mu_0=-3.0, v_0=0.6, sim_length=40):
    mu, v = mu_0, v_0
    for t in range(sim_length):
        mu = a * mu + b
        v = a**2 * v + c**2
        ax.plot(grid,
                norm.pdf(grid, loc=mu, scale=np.sqrt(v)),
                alpha=0.5)

fig, ax = plt.subplots()
plot_density_seq(ax)
plt.show()
_images/6295177d66ec5822fb42fd749821807a1d291d69bd1cf5782672693cbfcc49a9.png

Moreover, the limit does not depend on the initial condition.

For example, this alternative density sequence also converges to the same limit.

fig, ax = plt.subplots()
plot_density_seq(ax, mu_0=4.0)
plt.show()
_images/50807281e41cf1cc9ca00c2b850c770500e6e00601e8aca34f5ef22e25a1c40f.png

In fact it’s easy to show that such convergence will occur, regardless of the initial condition, whenever |a|<1.

To see this, we just have to look at the dynamics of the first two moments, as given in (32.3).

When |a|<1, these sequences converge to the respective limits

(32.4)#μ:=b1aandv=c21a2

(See our lecture on one dimensional dynamics for background on deterministic convergence.)

Hence

(32.5)#ψtψ=N(μ,v)as t

We can confirm this is valid for the sequence above using the following code.

fig, ax = plt.subplots()
plot_density_seq(ax, mu_0=4.0)

mu_star = b / (1 - a)
std_star = np.sqrt(c**2 / (1 - a**2))  # square root of v_star
psi_star = norm.pdf(grid, loc=mu_star, scale=std_star)
ax.plot(grid, psi_star, 'k-', lw=2, label="$\psi^*$")
ax.legend()

plt.show()
<>:7: SyntaxWarning: invalid escape sequence '\p'
<>:7: SyntaxWarning: invalid escape sequence '\p'
/tmp/ipykernel_5770/3420803857.py:7: SyntaxWarning: invalid escape sequence '\p'
  ax.plot(grid, psi_star, 'k-', lw=2, label="$\psi^*$")
_images/00ec94e4259ade6e30e501a349175e925646cfaa308db64935a10c3b64b47d05.png

As claimed, the sequence {ψt} converges to ψ.

We see that, at least for these parameters, the AR(1) model has strong stability properties.

32.3.1. Stationary distributions#

Let’s try to better understand the limiting distribution ψ.

A stationary distribution is a distribution that is a “fixed point” of the update rule for the AR(1) process.

In other words, if ψt is stationary, then ψt+j=ψt for all j in N.

A different way to put this, specialized to the current setting, is as follows: a density ψ on R is stationary for the AR(1) process if

XtψaXt+b+cWt+1ψ

The distribution ψ in (32.5) has this property — checking this is an exercise.

(Of course, we are assuming that |a|<1 so that ψ is well defined.)

In fact, it can be shown that no other distribution on R has this property.

Thus, when |a|<1, the AR(1) model has exactly one stationary density and that density is given by ψ.

32.4. Ergodicity#

The concept of ergodicity is used in different ways by different authors.

One way to understand it in the present setting is that a version of the law of large numbers is valid for {Xt}, even though it is not IID.

In particular, averages over time series converge to expectations under the stationary distribution.

Indeed, it can be proved that, whenever |a|<1, we have

(32.6)#1mt=1mh(Xt)h(x)ψ(x)dxas m

whenever the integral on the right hand side is finite and well defined.

Notes:

Example 32.2

If we consider the identity function h(x)=x, we get

1mt=1mXtxψ(x)dxas m

In other words, the time series sample mean converges to the mean of the stationary distribution.

Ergodicity is important for a range of reasons.

For example, (32.6) can be used to test theory.

In this equation, we can use observed data to evaluate the left hand side of (32.6).

And we can use a theoretical AR(1) model to calculate the right hand side.

If 1mt=1mXt is not close to ψ(x), even for many observations, then our theory seems to be incorrect and we will need to revise it.

32.5. Exercises#

Exercise 32.1

Let k be a natural number.

The k-th central moment of a random variable is defined as

Mk:=E[(XEX)k]

When that random variable is N(μ,σ2), it is known that

Mk={0 if k is oddσk(k1)!! if k is even

Here n!! is the double factorial.

According to (32.6), we should have, for any kN,

1mt=1m(Xtμ)kMk

when m is large.

Confirm this by simulation at a range of k using the default parameters from the lecture.

Exercise 32.2

Write your own version of a one dimensional kernel density estimator, which estimates a density from a sample.

Write it as a class that takes the data X and bandwidth h when initialized and provides a method f such that

f(x)=1hni=1nK(xXih)

For K use the Gaussian kernel (K is the standard normal density).

Write the class so that the bandwidth defaults to Silverman’s rule (see the “rule of thumb” discussion on this page). Test the class you have written by going through the steps

  1. simulate data X1,,Xn from distribution ϕ

  2. plot the kernel density estimate over a suitable range

  3. plot the density of ϕ on the same figure

for distributions ϕ of the following types

Use n=500.

Make a comment on your results. (Do you think this is a good estimator of these distributions?)

Exercise 32.3

In the lecture we discussed the following fact: for the AR(1) process

Xt+1=aXt+b+cWt+1

with {Wt} iid and standard normal,

ψt=N(μ,s2)ψt+1=N(aμ+b,a2s2+c2)

Confirm this, at least approximately, by simulation. Let

  • a=0.9

  • b=0.0

  • c=0.1

  • μ=3

  • s=0.2

First, plot ψt and ψt+1 using the true distributions described above.

Second, plot ψt+1 on the same figure (in a different color) as follows:

  1. Generate n draws of Xt from the N(μ,s2) distribution

  2. Update them all using the rule Xt+1=aXt+b+cWt+1

  3. Use the resulting sample of Xt+1 values to produce a density estimate via kernel density estimation.

Try this for n=2000 and confirm that the simulation based estimate of ψt+1 does converge to the theoretical distribution.