# Vector Autoregressive Models

Consider here some $VAR(1)$ model,

$\begin{bmatrix}Y_{1,t} \\ Y_{2,t}\end{bmatrix} = \begin{bmatrix}A_{1,1}&A_{1,2} \\ A_{2,1}&A_{2,2}\end{bmatrix}\begin{bmatrix}Y_{1,t-1} \\ Y_{2,t-1}\end{bmatrix} + \begin{bmatrix}\varepsilon_{1,t} \\ \varepsilon_{2,t}\end{bmatrix}$

We’ve seen in class that stationnarity of that time series, in the sense that $\mathbb{E}[\boldsymbol{Y}_t]=\boldsymbol{\mu}$ and $\text{Var}[\boldsymbol{Y}_t,\boldsymbol{Y}_{t-h}]=\boldsymbol{\Gamma}(h)$, was valid if the roots (in $\mathbb{C}$) of the characteristic polyonomial –$P(z)=\text{det}(\mathbb{I}-\boldsymbol{A}z)$ – were outside the unit circle.

To visualize this point, consider the following time series

$\begin{bmatrix}Y_{1,t} \\ Y_{2,t}\end{bmatrix} = \begin{bmatrix}0.7&0.4 \\ 0.2&0.3\end{bmatrix}\begin{bmatrix}Y_{1,t-1} \\ Y_{2,t-1}\end{bmatrix} + \begin{bmatrix}\varepsilon_{1,t} \\ \varepsilon_{2,t}\end{bmatrix}$

To generate that time series, we need to generate a bivariate white noise, i.e. $\text{Var}(\boldsymbol{\varepsilon}_t)=\boldsymbol{\Sigma}$ (not necessarily a diagonal matrix), and $\text{Var}(\boldsymbol{\varepsilon}_t,\boldsymbol{\varepsilon}_{t-h})=\boldsymbol{0}$. For instance

> n=500
> r=0.7
> set.seed(1)
> Z1=rnorm(n)
> Z2=rnorm(n)
> E1=Z1
> E2=r*Z1+sqrt(1-r^2)*Z2

To generate now our time series, use

> A=matrix(c(.7,.2,.4,.3),2,2)
> X1=X2=rep(0,n)
> for(t in 2:n){
+   X1[t]=A[1,1]*X1[t-1]+A[1,2]*X2[t-1]+E1[t]
+   X2[t]=A[2,1]*X1[t-1]+A[2,2]*X2[t-1]+E2[t]
+ }

Here, we have

> plot(X1,type="l",col="red")
> lines(X2,col="blue")

Those two time series seem to be stationnary. And, indeed,

> polyroot(c(1,-sum(diag(A)),det(A)))
[1] 1.18+0i 6.51-0i
> Mod(polyroot(c(1,-sum(diag(A)),det(A))))
[1] 1.18 6.51

# Base de Données de Classification

Vendredi matin, nous aurons un TP sur les méthodes de classification. Nous travaillerons sur la base de données suivante,

> source(
"http://freakonometrics.free.fr/ds_credit.R")

La description complète des variables (et des modalités) est en ligne sur archive.ics.uci.edu/ml/

# Forecast, Automatic Routines vs. Experience

This morning, in our Time Series course, we’ve been playing with some data I got from google.ca/trends/. Actually, we’ve been playing on some old version, downloaded 18 months ago (discussed in a previous post, in French).

> urls = "http://freakonometrics.free.fr/report-headphones-2015.csv"
> tail(report)
580 2015-02-08 - 2015-02-14         53
581 2015-02-15 - 2015-02-21         52
582 2015-02-22 - 2015-02-28         51
583 2015-03-01 - 2015-03-07         50
584 2015-03-08 - 2015-03-14         49
585 2015-03-15 - 2015-03-21         49

If we plot that weekly time series, we have

> plot(report[,2],type="l")

Working with weekly series is more complicated (at least to find a simple model, with only a few lags), so let us convert that series into a monthly one,

> source(
+   "http://freakonometrics.blog.free.fr/public/code/H2M.R")
> plot(headphones)