Introduction to Time Series II

Author: Edwin Bedolla

Date: Original, 6th April 2020. This version, 7th February 2021.

In this document, the main statistics such as the mean function, autocovariance function and autocorrelation function will be described, along with some examples.

We will import all of the necessary modules first.

15.1 μs
109 s
4.4 ms
11.2 ms

Descriptive statistics and measures

A full description of a given time series is always given by the joint distribution function of the time series which is a multi-dimensional function that is very difficult to track for most of the time series that are dealt with.

Instead, we usually work with what's known as the marginal distribution function defined as

Ft(x)=P{xtx}

where P{xtx} is the probability that the realization of the time series xt at time t is less or equal that the value of x. Even more common is to use a related function known as the marginal density function

ft(x)=Ft(x)x

and when both functions exist they can provide all the information needed to do meaningful analysis of the time series.

Mean function

With these functions we can now define one of the most important descriptive measures, the mean function which is defined as

μxt=E(xt)=xft(x)dx

where E is the expected value operator found in classical statistics.

Autocovariance and autocorrelation

We are also interested in analyzing the dependence or lack of between realization values in different time periods, i.e. xt and xs; in that case we can use classical statistics to define two very important and fundamental quantities.

The first one is known as the autocovariance function and it's defined as

γx(s,t)=cov(xs,xt)=E[(xsμs)(xtμt)]

where cov is the covariance as defined in classical statistics. A simple way of defining the autocovariance is the following

The autocovariance tells us about the linear dependence between two points on the same time series observed at different times.

Normally, we know from classical statistics that if for a given time series xt we should have γx(s,t)=0 then it means that there is no linear dependence between xt and xs at time periods t and s; but this does not mean that there is no relation between them at all. For that, we need another measure that we describe below.

We now introduce the autocorrelation function (ACF) and it's defined as

ρ(s,t)=γx(s,t)γx(s,s)γx(t,t)

which is a measure of predictability and we can define it in words as follows

The autocorrelation measures the linear predictability of a given time series xt at time t, using values from the same time series but at time s.

This measure is very much related toPearson's correlation coefficient from classical statistics, which is a way to measure the relationship between values.

The range of values for the ACF is 1ρ(s,t)1; when ρ(s,t)=1 it means that a linear model can perfectly describe the realization of the time series at time t provided with the realization at time s, e.g. a trend goind upwards, on the other hand, if ρ(s,t)=1 would mean that the realization of the time series xt decrease while the realization xs is increasing.

29.4 μs

Example

Let's look at an example for the particular case of the moving average. We will be working out the analytic form of the autocovariance function and ACF for the moving average while also providing the same results numerically using Julia.

Recall the 3-valued moving average to be defined as

vt=13(wt1+wt+wt+1)

Let's plot the moving average again. We will create a very big time series for the sake of numerical approximation below.

First, we create the white noise time series.

17.1 μs
37.9 ms
4.8 ms
5.3 ms

Then, as before, we compute the 3-valued moving average.

10.2 μs
305 ms
73.4 ms

Recall what these look like in a plot. We just plot the first 100 elements in the time series to avoid having a very cluttered plot.

9.8 μs
227 ns
32.6 ms

We are now ready to do some calculations. First, we invoke the definition of the autocovariance function and apply it to the moving average

γv(s,t)=cov(vs,vt)=cov{13(wt1+wt+wt+1),13(ws1+ws+ws+1)}

and now we need to look at some special cases.

  • When s=t we now have the following

γv(t,t)=cov(vt,vt)=cov{13(wt1+wt+wt+1),13(wt1+wt+wt+1)}

then, by the property of covariance of linear combinations we have the following simplification

γv(t,t)=cov(vt,vt)=19{cov(wt1,wt1)+cov(wt,wt)+cov(wt+1,wt+1)}

and because cov(U,U)=var(U) for a random variable U, for a white noise random variable we have var(wt)=σwt2, thus

γv(t,t)=cov(vt,vt)=39σwt2

In this case, recall that our white noise is normally distributed wtN(0,σwt2) with σwt2 so the true expected value is the following

21.7 μs
true_γ
0.3333333333333333
87.0 ns

We will try to compute the autocovariance function using classical statistics by means of the cov function in Julia. We need to pass it the time series like so

9.8 μs
γ_jl
0.33351433375298867
152 ms

And we can see that the value is quite similar. The error must come from the fact that we may need a bigger ensemble of values, but this should suffice.

7.7 μs
  • When s=t+1 we now have the following

γv(t+1,t)=cov(vt+1,vt)=cov{13(wt+wt+1+wt+2),13(wt1+wt+wt+1)}γv(t+1,t)=19{cov(wt,wt)+cov(wt+1,wt+1)}γv(t+1,t)=29σwt2

So the true value is now

15.4 μs
true_γ1
0.2222222222222222
91.0 ns

To check this, we perform the same operations as before, but this time, we need to move the time series one time step with respect to itself.

14.6 μs
γ_jl1
0.22247427287331825
49.7 ms

Great! Within a tolerance value, this is quite a nice estimate. It turns out that for the cases s=t+h where h2, the value for the autocovariance is zero. We'll check it numerically here.

13.2 μs
γ_jl_zero
0.00043227901205739896
4.8 ms

It's actually true, a value very close to zero but, ¿why? It's easy to see if one applies the autocovariance function definition and checks the case s=t+3, and so on.

Let's now focus on the ACF for a 3-valued moving average. We have several cases, like before.

11.2 μs
  • When s=t we now have the following

ρv(t,t)=γv(t,t)γv(t,t)γv(t,t)ρv(t,t)=γv(t,t)γv(t,t)=1

so it turns out that the true value is ρv(t,t)=1, and we can check this using the cor function to compute the correlation coefficient in Julia as an estimate for the ACF

12.7 μs
ρ_est
1.0
25.8 ms
  • When s=t+1 we now have the following

ρv(t+1,t)=γv(t+1,t)γv(t+1,t+1)γv(t,t)

recall from before that γ(t,t)=3/9σvt2 for a white noise time series, and we also have γ(t+1,t)=2/9σvt2, so the ACF is now

ρv(t+1,t)=2/9σvt2(3/9σvt2)(3/9σvt2)ρv(t+1,t)=18σvt227σvt2ρv(t+1,t)=23

which is the true value

16.2 μs
true_ρ2
0.6666666666666666
68.0 ns

and again, we can check this value numerically

19.9 μs
ρ_est2
0.667060850012139
5.5 ms

Lastly, like with the autocovariance, the ACF for the cases s=t+h where h2 is zero as seen below

13.7 μs
ρ_est_zero2
0.0012961321840730129
1.9 ms