Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1.4 Basic Time Series Models

White Noise

A central model we will use throughout this textbook is white noise.

In the context of time series, white noise is defined as a sequence of random variables wtw_t with mean 0 and (finite) variance σw2\sigma_w^2, denoted as[1]:

wtwn(0,σw2)w_t \sim wn(0, \sigma_w^2)

In cases in which the mean is not zero, we can always subtract the mean to treat the remaining noise as white. We will often require the noise to be independent and identically distributed (iid). In particular, we will frequently use Gaussian white noise:

wtN(0,σw2)w_t \sim \mathcal{N}(0, \sigma_w^2)

Visualizing White Noise

Simulated white noise process.

Figure 1:Simulated white noise process.

Smoothed version of white noise.

Figure 2:Smoothed version of white noise.

The following code lets you play around with different values for the noise and distributions. Note that if you are reading this in GitHub pages you will not be able to run the cell, you’ll either need to download the book or simpy copy and paste the code into a Jupyter notebook.

import numpy as np
import matplotlib.pyplot as plt

standard_deviation = 1.0 # Play around with this parameter!
white_noise = np.random.normal(loc=0.0, scale=standard_deviation, size=1000)
# We can also look at alternative distributions. Uncomment the following to use a Cauchy distribution instead.
# white_noise = np.random.standard_cauchy(size=1000)
plt.plot(np.arange(0, 1000, 1), white_noise)
plt.show()

Moving Average

Figure 1 and Figure 2 suggest one model for introducing temporal correlation in a series.

In a moving average (also known as a rolling average), each value is replaced by the average of that value and a selection of its neighbors.

Simple Three-Value Moving Average

For example, a simple centered three-value moving average would define vtv_t as:

vt=13(wt1+wt+wt+1)v_t\stackrel{\triangle}{=}\frac{1}{3}(w_{t-1} + w_t + w_{t+1})

where =\stackrel{\triangle}{=} is read as “is defined as.”

Even if the wtw_t’s are iid, the vtv_t’s will be serially correlated.

Example: Consider:

Both v2v_2 and v3v_3 depend on the values w2w_2 and w3w_3, creating correlation between consecutive observations despite wtw_t being iid.

Weighted Moving Average

Other weighting schemes are possible, for example:

vt=110wt2+210wt1+410wt+210wt+1+110wt+2v_t\stackrel{\triangle}{=}\frac{1}{10}w_{t-2}+\frac{2}{10}w_{t-1}+\frac{4}{10}w_{t}+\frac{2}{10}w_{t+1}+\frac{1}{10}w_{t+2}

This gives more weight to the central observation while still incorporating information from neighbors.

Random Walk

Applying a moving average to uncorrelated noise is one plausible method for introducing temporal correlation. Another scenario is when each time step starts from the value of the previous point (e.g., a stock price that opens trading at yesterday’s closing price).

Basic Random Walk

This suggests a model of the form:

xt=xt1+wtx_t = x_{t-1} + w_t

where xtx_t is the value of the series xx at time tt and the wtw_t’s are iid white noise.

Random Walk with Drift

If there is also an underlying trend (e.g., a stock’s long-term price going up), we can add a constant drift term δ\delta:

xt=δ+xt1+wtx_t = \delta + x_{t-1} + w_t
Simulated random walk with w_t \sim \mathcal{N}(0, 1^2) showing apparent trends.

Figure 3:Simulated random walk with wtN(0,12)w_t \sim \mathcal{N}(0, 1^2) showing apparent trends.

We can simulate a random walk starting with our white noise and using the np.cumsum function—if you don’t understand why yet don’t worry, we’ll address it in later chapters. For now, this cell lets you get an idea of what random walks might look like. As before, you may need to copy and paste into a Jupyter notebook.

import numpy as np
import matplotlib.pyplot as plt

standard_deviation = 1.0 # Play around with this parameter!
white_noise = np.random.normal(loc=0.0, scale=standard_deviation, size=1000)
# We can also look at alternative distributions. Uncomment the following to use a Cauchy distribution instead.
# white_noise = np.random.standard_cauchy(size=1000)
plt.plot(np.arange(0, 1000, 1), np.cumsum(white_noise))
plt.show()

We will return to random walks and their cousins extensively throughout the book.

Autoregression

The concept of a random walk can be generalized to autoregressive processes.

Second Order Autoregression Example

Below we present a simulated autoregressive process generated by:

xt=1.5xt10.9xt2+wtx_t = 1.5 x_{t-1} - 0.9 x_{t-2} + w_t
Simulated AR(2) process.

Figure 4:Simulated AR(2) process.

Note the long-range patterns, despite the fact that the model can only “remember” two time steps into the past. Autoregressive models have surprising ability to capture complex dynamics.

Signal and Noise

In many real-life scenarios, we consider our signal to be formed by the addition of white noise to an underlying process.

Separating signal from noise is a central focus in signal processing, with applications to:

Example: Sinusoidal Signal with Noise

Signal 2\sin\left(\frac{2\pi t}{20} + \frac{3}{5}\pi\right) + w_t for w_t \sim \mathcal{N}(0,0^2), 
\mathcal{N}(0,1^2), and \mathcal{N}(0, 5^2).

Figure 5:Signal 2sin(2πt20+35π)+wt2\sin\left(\frac{2\pi t}{20} + \frac{3}{5}\pi\right) + w_t for wtN(0,02)w_t \sim \mathcal{N}(0,0^2), N(0,12) \mathcal{N}(0,1^2), and N(0,52)\mathcal{N}(0, 5^2).

As the variance of the noise increases, it becomes progressively more difficult to recover the underlying signal. Much of time series analysis is concerned with developing methods to extract meaningful patterns from noisy observations.

Footnotes
  1. The notation used in this book is explained in the appendix.