9.1 Time Domain and Frequency Domain Analysis
- x =
acf
(y {,k})
- computes the autocorrelation function of a time series
-
acfplot
(y {,k})
- plots the autocorrelation function of a time series
- x =
pacf
(y,k)
- computes the partial autocorrelation function of a time series
-
pacfplot
(y {,k})
- plots the partial autocorrelation function of a time series
- x =
pgram
(x { opt})
- computes and plots the raw (log) periodogram of a time series
- x =
spec
(y {,width {,opt}})
- estimates and plots the spectral density of a time series
-
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
. The subscript
(
) 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
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
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)
The resulting graph is shown in Figure 9.1.
Figure:
First 250 observations of
dmus58
.
|
9.1.1 Autocovariance and Autocorrelation Function
The sample autocovariance function at lag
of a
process
is defined for
as
where
is the arithmetic mean of the
time series
.
We define the sample autocorrelations
of the process by
standardizing the sample autocovariance function
by
(the sample variance of the process), i.e.
Let's consider a sample of 500 independent realizations of a standard
normal random variable:
randomize(0)
y = normal(500)
Using
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
acfplot
which displays the correlogram, i.e. the graph of
the autocorrelation function
. Type
acfplot(y)
to get the following graph in Figure 9.2.
Confidence levels
are plotted to easily check the assumption
that the series is a white noise.
Figure 9.2:
Autocorrelation function.
|
As another useful measure,
the partial autocorrelations are implemented
in
pacf
. The partial autocorrelation of order
is calculated as the
correlation of the two residuals obtained after regressing
and
on the intermediate observations
, the partial autocorrelation
at lag 1 being defined as the correlation between
and
.
XploRe
also provides the function
pacfplot
as a partial autocorrelation equivalent to
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.
|
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
with
the angular frequencies in
and
the theoretical autocovariances.
Since the spectrum is symmetric around zero, the analysis is
restricted to the range of frequencies in
. For a sample of
observations, we consider the harmonic frequencies, or
Fourier frequencies
,
. The sample counterpart
of the spectrum is the periodogram, defined as
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
pgram
computes and plots the periodogram of the
series.
XploRe
computes the periodogram for the frequencies
, which are linked to the angular frequencies by the
relationship
. The periodogram of our
generated series of independent normal random variables
can be
obtained as follows:
z = pgram(y)
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.)
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
spec
that will be introduced in more details in the following section.