9.1 Time Domain and Frequency Domain Analysis


x = 17937 acf (y {,k})
computes the autocorrelation function of a time series
17940 acfplot (y {,k})
plots the autocorrelation function of a time series
x = 17943 pacf (y,k)
computes the partial autocorrelation function of a time series
17946 pacfplot (y {,k})
plots the partial autocorrelation function of a time series
x = 17949 pgram (x { opt})
computes and plots the raw (log) periodogram of a time series
x = 17952 spec (y {,width {,opt}})
estimates and plots the spectral density of a time series
17955 timeplot (y {,len {,header}})
plots a time series in multiple windows with user-specified maximum length per window
A time series represents a path (realization) of a stochastic process $ \{Y_t \}$. The subscript $ t$ ( $ t=1,\dots,T$) is usually understood as a time index (e.g. days or years). In this section we will consider that the underlying stochastic process is weakly stationary, i.e. we will assume that it satisfies the conditions
$\displaystyle E \, \vert Y_t\vert^2$ $\displaystyle <$ $\displaystyle \infty \quad \forall t,$  
$\displaystyle E \, Y_t$ $\displaystyle =$ $\displaystyle \mu \quad \forall t,$  
$\displaystyle E \, (Y_t-\mu)(Y_s-\mu)$ $\displaystyle =$ $\displaystyle E \, (Y_{t+\tau}-\mu)(Y_{s+\tau}-\mu) \quad \forall s,\, t,\, \tau.$  

All functions for the time series analysis are part of the times library and become available after loading this library:

  library("times")
To display a time series we use 17960 timeplot . The following example plots the first 250 observations of the time series dmus58 (Deutschmark-Dollar FX rates in 1982):
  y = read("dmus58")
  y = y[1:250,]
  timeplot(y)
17966 XLGtimes01.xpl

The resulting graph is shown in Figure 9.1.

Figure: First 250 observations of dmus58 .
\includegraphics[scale=0.425]{times01}


9.1.1 Autocovariance and Autocorrelation Function

The sample autocovariance function at lag $ \tau $ of a process $ Y_t$ is defined for $ \tau \in \{ 0,\dots, T-1 \}$ as

$\displaystyle \widehat{\gamma}(\tau) = T^{-1} \sum_{t = \tau+1}^T (Y_t - \overline{Y})
(Y_{t-\tau} - \overline{Y})
$

where $ \overline{Y}= T^{-1} \sum_{t = 1}^T Y_t$ is the arithmetic mean of the time series $ Y_t$. We define the sample autocorrelations $ \widehat{\rho}(\tau)$ of the process by standardizing the sample autocovariance function $ \widehat{\gamma}(\tau)$ by $ \widehat{\gamma}(0)$ (the sample variance of the process), i.e.

$\displaystyle \ \widehat{\rho}(\tau) = \frac{\widehat{\gamma}(\tau)}{\widehat{\gamma}(0)}.
$

Let's consider a sample of 500 independent realizations of a standard normal random variable:

  randomize(0)
  y = normal(500)
18094 XLGtimes02.xpl

Using 18099 acf we can evaluate the sample autocorrelations of the generated series. In the following example the result is stored in the vector x and the first five autocorrelations are displayed:
  x = acf(y)
  x[1:5]
The shape of the autocorrelation function may be easily analyzed using the function 18102 acfplot which displays the correlogram, i.e. the graph of the autocorrelation function $ \widehat\rho(\tau)$. Type
  acfplot(y)
to get the following graph in Figure 9.2. Confidence levels $ \pm 2 / \sqrt{T}$ are plotted to easily check the assumption that the series is a white noise.

Figure 9.2: Autocorrelation function.
\includegraphics[scale=0.425]{times02}

As another useful measure, the partial autocorrelations are implemented in 18106 pacf . The partial autocorrelation of order $ \tau \geq 2$ is calculated as the correlation of the two residuals obtained after regressing $ Y_{\tau+1}$ and $ Y_1$ on the intermediate observations $ Y_2, \dots, Y_{\tau}$, the partial autocorrelation at lag 1 being defined as the correlation between $ Y_1$ and $ Y_2$.

XploRe also provides the function 18113 pacfplot as a partial autocorrelation equivalent to 18116 acfplot . The usage of these two quantlets is similar to the previously mentioned autocorrelation function. To evaluate the sample partial autocorrelations of the generated series and plot the evaluated values type the following instructions:

  x = pacf(y,5)
  x[1:5]
  pacfplot(y)
The resulting plot is shown in Figure 9.3.

Figure 9.3: Partial autocorrelation function.
\includegraphics[scale=0.425]{times02a}


9.1.2 The Periodogram and the Spectrum of a Series

The frequency domain analysis is concerned with the decomposition of the observed series into periodic components. The main analytical tool for spectral analysis is the spectrum of a series defined as

$\displaystyle f(\lambda) = (2\pi)^{-1} \left[ \gamma(0) + 2 \sum_{\tau = 1}^\infty
\gamma(\tau) \cos(\lambda \tau)\right]\,,
$

with $ \lambda$ the angular frequencies in $ [-\pi,\pi]$ and $ \gamma(\tau)$ the theoretical autocovariances. Since the spectrum is symmetric around zero, the analysis is restricted to the range of frequencies in $ [0,\pi]$. For a sample of $ T$ observations, we consider the harmonic frequencies, or Fourier frequencies $ \lambda_j = 2 \pi j/T$, $ j=1,\ldots,[T/2]$. The sample counterpart of the spectrum is the periodogram, defined as

$\displaystyle \ I(\lambda) = (2\pi)^{-1} \left[ \widehat{\gamma}(0) + 2 \sum_{\tau = 1}^{T-1}
\ \widehat{\gamma}(\tau) \cos(\lambda \tau)\right].
$

The periodogram is not a consistent estimator of the spectrum. When the sample size tends to infinity, more frequencies are considered without adding more precision on a particular one. The function 18233 pgram computes and plots the periodogram of the series. XploRe computes the periodogram for the frequencies $ k_j \in
[0,0.5]$, which are linked to the angular frequencies by the relationship $ k_j = \lambda_j/(2\pi)$. The periodogram of our generated series of independent normal random variables $ Y_t$ can be obtained as follows:
  z = pgram(y)
18241 XLGtimes03.xpl

The periodogram for the series y is computed, the result is stored in the variable z and the periodogram is displayed on the screen (Figure 9.4.)

Figure 9.4: Periodogram.
\includegraphics[scale=0.425]{times03}

The jagged shape of the periodogram illustrates the typical feature of a white noise series, i.e. a series of independent and identically distributed random variables. The lack of smoothness of the periodogram makes it difficult to interpret. In order to estimate the spectrum, the periodogram can be smoothed using the function 18247 spec that will be introduced in more details in the following section.