iTranslated by AI
Introduction to Time Series Analysis: Part 2
Overview
In the previous post, I explained the preprocessing of time series data. Time series data that has undergone appropriate preprocessing has very easy-to-analyze properties: stationarity, normality, and linearity.
In this post, I will explain the main quantities in stationary time series. This is an essential technique for more accurately understanding the characteristics of stationary time series data. I will mainly discuss univariate cases (single time series data), but I also plan to touch on multivariate cases.
Stationary Time Series
Let's look into the stationarity of time series.
First, regardless of whether stationarity exists, let's define the following three statistics. Here, if the time series data is
- Mean:
\mu_n = E[y_n] - Variance:
Var(y_n) = E[(y_n - \mu_n)^2] - Covariance:
Con(y_n, y_m) = E[(y_n - \mu_n)(y_m - \mu_m)]
Now, stationarity means "the probability structure (properties) does not change over time," and it is divided into strict stationarity and weak stationarity depending on the rigor of the conditions.
Strict Stationarity and Weak Stationarity
Strict stationarity occurs when the probability distribution underlying the time series data does not change over time. For any set of time points
In practice, it is difficult to verify this strict stationarity, and since such strong conditions are often not required, we frequently consider the following weak stationarity.
Weak stationarity means that the mean, variance, and covariance do not change over time (invariance up to the second-order moment). In other words, for any time difference (shift amount)
Clearly, strict stationarity is a more rigorous condition than weak stationarity. Therefore, if a process is strictly stationary and its mean, variance, and covariance exist, it also satisfies weak stationarity. The reverse is not necessarily true.
:::
Autocovariance function of weakly stationary time series
To re-organize the properties of weak stationarity:
- The mean
does not depend on timeE[y_n] ; that is, it can be written asn .E[y_n] = \mu - The covariance
depends only on the time differenceCov(y_n, y_m) . That is,k Cov(y_n, y_{n-k}) = E[(y_n - E[y_n])(y_{n-k} - E[y_{n-k}])] =E[(y_n - \mu)(y_{n-k} - \mu)] = C_k
In particular, the following properties of the autocovariance
Autocovariance function is an even function
An even function is a function with the property
Here, it states that
Proof:
In equation (6), we used the fact that "covariance is invariant even if the elements are swapped," and in equation (7), we used the fact that "from weak stationarity, shifting by the same amount is not a problem."
|C_k| \leq C_0
We use the general fact that
Derivation for enthusiasts
For any
Breaking this down further:
Now, if we fix the values of
Here, by setting
From this, we get
Positive semi-definite
Positive semi-definiteness means that the following holds:
Due to this property, a convenient solution method called the Yule-Walker equations can be used.
Derivation:
The transition from equation (11) to (12) is based on the replacement with the autocovariance
Autocorrelation function of weakly stationary time series
Related to autocovariance, another quantity is the autocorrelation function.
This is defined as follows:
However, in the case of a stationary time series, it can be rewritten very simply.
In other words, if the autocovariance function
How to find various estimators
We obtain the mean, autocovariance function, and autocorrelation function from the time series data
- Sample mean
- Sample autocovariance function
- Sample autocorrelation function
Note that the sample autocovariance function calculates the sum of autocovariances with data from lag
In fact, this
Proof that it is not an unbiased estimator
If the denominator is
For now, let's establish the properties of the estimators:
White Noise
Now that we understand how to obtain the estimators for the mean, autocovariance, and autocorrelation, I will explain white noise, which is an extremely important type of time series data in time series analysis.
White noise has the properties that the expected value (mean)
plot(as.ts(rnorm(1000))) # White noise (generating 1000 random numbers from a standard normal distribution)

To define it more rigorously, it can be expressed as follows:
Due to these properties of autocovariance, the autocorrelation function, which is found as a ratio of autocovariances, is:
Now, since white noise is naturally a weakly stationary time series, we can calculate the estimators for the mean, autocovariance, and autocorrelation as described above. If we calculate these specifically for the case of white noise:
Derivation for enthusiasts
First, the expected value of the estimator
And since the variance of the estimator
Regarding equation (28), when
The variance of the autocorrelation function estimator for white noise follows a normal distribution
Conversely, if the time series data being handled is white noise, the autocorrelation function should fall within
For example, the following plot shows the autocorrelation coefficients for the white noise data mentioned earlier, with

wn <- as.ts(rnorm(1000))
wn <- unicor(wn, plot = FALSE) # Simultaneously find mean, autocovariance, and autocorrelation for univariate data
# Autocorrelation function of white noise:
plot(wn$acov, ylim = c(-1,1), col = 1, type = "l")
par(new = T)
# Plot of 1/√N (red)
plot(wn$acov.err, ylim = c(-1,1), col = 2, type = "l", ann = F)
par(new = T)
plot(-wn$acov.err, ylim = c(-1,1), col = 2, type = "l", ann = F)
In this figure, the horizontal axis represents the time lag
Next, if we do the same with Sunspot data:
data(Sunspot)
unicor(Sunspot)

First, looking at the autocorrelation function alone, there is a very clear periodicity, and it can be seen that the decay is slow. In other words, it reveals a property where there are lags (periods) where the correlation becomes very strong, and the influence remains large even at points in time that are somewhat distant.

Furthermore, it is clear that the values hardly fall within the region of the red reference lines (
Visualization of Periodicity
Next, we will represent the data in spectral representation using the autocovariance function. In spectral representation, by converting time series data from the time axis to the frequency axis, it is possible to reveal periodic movements contained in the time series data, regardless of time.
...That said, some might say they don't quite get it (I am one of those not used to spectral representation myself).
Therefore, while acknowledging that it might lack some precision, I would like to rephrase it in words that are easier to understand.
In other words, time series data that fluctuates over time is considered to be actually realized by synthesizing multiple periodic functions (waves; like cosine or sine waves). Spectral representation can be said to be the task of decomposing the multiple waves that make up the time series data based on the magnitude of these periods.
By using spectral representation, it becomes possible to analyze what kind of periodic waves are included and at what magnitude.
Spectral Representation
Now, this (power) spectrum can actually be obtained through the Fourier transform of the previously mentioned autocovariance function
It can be expressed as follows. In a univariate stationary time series, since the autocovariance
It can be rewritten as follows. As can be seen from the equation, this power spectrum is an even function.[4]
Also, it is possible to transform the power spectrum back into the autocovariance
Inverse Fourier transform derivation for enthusiasts
Periodogram
It was found that the power spectrum
In actual practice:
- First, train a time series model on the data to obtain
, an estimator of autocovariance.\hat{C}_k - Fourier transform
to obtain\hat{C}_k , an estimator of the power spectrum.\hat{p}(f)
Since time series data is finite, the resulting estimator of the autocovariance is also finite. Therefore, the estimator of the power spectrum
A plot of this power spectrum estimator
data(WHARD) # WHARD data in the TSSS package
period(WHARD, window = 0) # Create a periodogram: window = 0 means no smoothing (described later)

The above shows a periodogram created for the WHARD data (monthly wholesale sales data for certain hardware). It can be seen that the spectrum increases at regular intervals. In fact, since there are points that increase every 12 intervals, it appears to have a 12-month periodicity.
By looking at the power spectrum or periodogram, you can analyze what kind of periodic waves are included and at what intensity, so it is a good idea to create one when analyzing time series data.
Properties of the Periodogram
Here, I'll mention that as a property of the periodogram, it is an unbiased estimator, but not a consistent estimator.
What this means is that while the expected value approaches the true spectral density function
As an example, I created periodograms for time series data generated from white noise, increasing the data size to 200, 800, and 3,200 points.
r <- rnorm(3200) # Generate random numbers
spec.pgram(as.ts(r[1:200]), log = "yes")
spec.pgram(as.ts(r[1:800]), log = "yes")
spec.pgram(as.ts(r[1:3200]), log = "yes")

Looking at the figure, as the data size increases, the mean of the spectrum approaches 1, but the variance does not particularly improve.[6]
To create a better periodogram, there is a technique where the entire data is divided into sub-intervals, periodograms are obtained for the data in each interval, and finally, they are averaged. Using this, you can reduce the variance of the spectrum by a factor of
Using this, I compared the case where 3,200 white noise data points are 1) used in full (3,200 points), 2) split into 2 segments of 1,600 points each, 3) split into 4 segments of 800 points each, and 4) split into 16 segments of 200 points each.
(The R code was borrowed from this site.)

As you can see from the figure, the variance decreases as the number of divisions increases.
Additionally, smoothing of the periodogram can also be performed. This is based on the assumption that spectra should naturally be smooth.
Although I will omit the details, in R, you can create a smoothed periodogram using the window option of the period function in the TSSS package.
Multivariate Time Series
Finally, I will briefly explain the case of multivariate time series. In time series analysis, multivariate (
As an example, we will handle the HAKUSAN data in the TSSS package (recording the yaw rate, rolling, pitching, and rudder angle of a ship every second; 4 variables).
data(HAKUSAN)
plot(HAKUSAN[,1])

The figure shows the 4-variable time series data plotted together on the same time axis.
Let's extend the autocovariance and autocorrelation functions obtained for the univariate case to define the cross-covariance and cross-correlation functions between two time series datasets.
Cross-covariance Function of Stationary Time Series
The above equation defines the cross-covariance function between the
Then, we define the cross-covariance function matrix calculated between all
Note that in the multivariate case, the cross-covariance function is not an even function. Generally, it can be written as:
Proof
Regarding equations (31) and (32), the invariance of the result when swapping covariance elements is used. In equations (33) and (34), the fact that results are invariant for shifts that maintain the time difference
Cross-correlation Function of Stationary Time Series
The above equation defines the cross-correlation function between the
As with the cross-covariance function, the cross-correlation function matrix calculated between all
Calculating the cross-correlation function for the HAKUSAN data yields the following (the crscor function in the TSSS package is convenient):
data(HAKUSAN)
y <- as.matrix(HAKUSAN[, 1:4])
crscor(y)

Visualizing this shows that the cross-correlation coefficients between time series datasets strengthen or weaken at certain time differences
Component Decomposition
All of them fluctuate irregularly, but there is a possibility that some kind of interaction is occurring between the time series datasets. For example, fluctuations in the yaw rate might be affecting fluctuations in rolling... and interestingly, the reverse could also be true.
In the multivariate case, each individual time series is generated as a result of complex interactions between the datasets, so it is necessary to decompose the components appropriately. While I plan to provide a detailed explanation in a future post on "Estimation of Time Series Models," I will only show the results of component decomposition here.
# Multivariate cross-spectrum (TSSS package)
data(HAKUSAN)
yy <- as.matrix(HAKUSAN[, 1:4])
nc <- dim(yy)[1]
n <- seq(1, nc, by =2)
y <- yy[n, ]
z <- marfit(y, lag = 20)
marspc(z$arcoef, v = z$v, col = c(1,2,3,4,5))

The figure above shows the power decomposition and power contribution rates for the HAKUSAN data, calculated from the power spectra of each component (yaw rate, rolling, pitching, and rudder angle of the ship).
By looking at the power spectrum in a univariate case, we could determine which frequency component waves appeared strongly. However, in the multivariate case, a particular frequency component in one time series is not composed solely of that data itself. In fact, it includes influences from other components (time series data).
Therefore, through power decomposition and power contribution rates, it is possible to understand to what extent the spectrum of a certain time series is influenced by itself or by other time series data.
In the figure, for example, from the power spectrum of the rudder angle (D), it can be seen that the rudder angle (D) data mainly contains waves with a frequency of 0.13-0.14. However, looking at the power contribution rate on the right, the influence of the yaw rate (A) also increases. In other words, the power decomposition reveals that the yaw rate (A) has a significant contribution to the rudder angle (D) data.
Summary
In this post, I organized the properties of (weakly) stationary time series data. If the autocovariance function
Next, I will finally introduce time series models and touch on parameter estimation and model selection.
Miscellaneous Notes
This time, the discussion became somewhat theoretical. Since I'm not originally strong with theory or formulas, there might be mistakes, but I would appreciate it if you could point them out kindly.
However, I feel that learning from the theory helps me grasp the key points of time series analysis.
(Writing formulas in Markdown is quite a task, though 💦)
References
Borrowed the code for the averaging process of the periodogram.
A lecture on time series analysis by Professor Kitagawa. I referred to the explanation content extensively this time as well.
A collection of practical application examples of time series analysis edited by Professors Akaike and Kitagawa. It provides many insights into the techniques of time series analysis and the interpretation of results in practical applications. I hope to introduce this book someday.
TSSS, the package providing the R code and datasets used in this post.
For those who want to know the properties of the Cauchy distribution.
-
Theoretically,
for white noise, but because some noise is included in the estimation, the variance is not zero. ↩︎R_k = 0 -
Since the number of data points is 1000 here, the red reference lines are drawn at approximately
. ↩︎\pm 0.03 -
Many time series analysis software packages and libraries plot these decision lines together for whiteness evaluation. ↩︎
-
Since
andC_k are even functions, and\cos(x) is a linear combination of them. ↩︎p(f) -
If drawn as a graph, it's like drawing a horizontal line where
. ↩︎p(f) = C_0 -
Since the spectrum of white noise is constant at
(as it is a standard normal distribution here) regardless of frequency. ↩︎\sigma^2 = 1
Discussion