1. Time Domain and Frequency Domain Analysis


x = 1072 acf (y {,k})
computes the autocorrelation function of a time series
1075 acfplot(y {,k})
plots the autocorrelation function of a time series
x = 1078 pacf (y,k)
computes the partial autocorrelation function of a time series
1081 pacfplot(y {,k})
plots the partial autocorrelation function of a time series
x = 1084 pgram (x { opt})
computes and plots the raw (log) periodogram of a time series
x = 1087 spec (y {,width {,opt}})
estimates and plots the spectral density of a time series
1090 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 {Yt }. 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

\begin{eqnarray*}
E \, \vert Y_t\vert^2 &<& \infty \quad \forall t,\\
E \, Y_t ...
..., (Y_{t+\tau}-\mu)(Y_{s+\tau}-\mu) \quad \forall s,\, t,\, \tau.
\end{eqnarray*}


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 1095 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)
1101times01.xpl

The resulting graph is shown in Figure 1.

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


1.1 Autocovariance and Autocorrelation Function

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

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

where $\overline{Y}= T^{-1} \sum_{t = 1}^T Y_t$ is the arithmetic mean of the time series Yt. 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.

\begin{displaymath}
\widehat{\rho}(\tau) = \frac{\widehat{\gamma}(\tau)}{\widehat{\gamma}(0)}.
\end{displaymath}

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

  randomize(0)
  y = normal(500)
1112times02.xpl

Using 1117 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 1120 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 2. Confidence levels $\pm 2 / \sqrt{T}$ are plotted to easily check the assumption that the series is a white noise.

Figure 2: Autocorrelation function.
\includegraphics[scale=0.6]{times02.ps}

As another useful measure, the partial autocorrelations are implemented in 1124 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 Y1 on the intermediate observations $Y_2, \dots, Y_{\tau}$, the partial autocorrelation at lag 1 being defined as the correlation between Y1 and Y2. XploRe also provides the function 1131 pacfplot as a partial autocorrelation equivalent to 1134 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 3.

Figure 3: Partial autocorrelation function.
\includegraphics[scale=0.6]{times02a.ps}


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

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

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

\begin{displaymath}
I(\lambda) = (2\pi)^{-1} \left[ \widehat{\gamma}(0) + 2 \su...
... = 1}^{T-1}
\widehat{\gamma}(\tau) \cos(\lambda \tau)\right].
\end{displaymath}

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 1140 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 Yt can be obtained as follows:
  z = pgram(y)
1148times03.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 4.)

Figure 4: Periodogram.
\includegraphics[scale=0.6]{times03.ps}

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 1154 spec that will be introduced in more details in the following section.



Method and Data Technologies   MD*TECH Method and Data Technologies
  http://www.mdtech.de  mdtech@mdtech.de