ECM.EngleGran: VGLTSM family function for the Two-dimensional...

View source: R/ECMEngleGran.R

ECM.EngleGranR Documentation

VGLTSM family function for the Two–dimensional Error–Correction Model (Engle and Granger, 1987) for I(1)–variables


Estimates a bidimensional error-correction model of order–(K, L), as proposed by Engle–Granger (Two step–approach; 1987), with bivariate normal errors by maximum likelihood estimation using Fisher scoring.


      ECM.EngleGran(ecm.order = c(1, 1),
                    zero = c("var", "cov"),
                    resids.pattern = c("intercept", "trend",
                                       "neither", "both")[1],
                    lag.res = 1, 
                    lmean = "identitylink",
                    lvar  = "loglink",
                    lcov  = "identitylink",
                    ordtsDyn = 0)



Length–2 (positive) integer vector. The order of the ECM model.


Integer or character–string vector. Details at zero.


Character. How the static linear regression y_{2, t} \sim y_{1, t} must be settle to estimate the residuals \widehat{z_t}. The default is a linear model with intercept, and no trend term. See below for details.


Numeric, single positive integer. The error term for the long–run equilibrium path is lagged up to order lag.res. See below for further details.

lmean, lvar, lcov

Same as MVNcov.


Positive integer. Allows to compare the estimated coefficients with those provided by the package 'tsDyn'. See below for further details.


This is an implementation of the two–step approach as proposed by Engle–Granger [1987] to estimate an order–(K, L) bidimensional error correction model (ECM) with bivariate normal errors.

This ECM class models the dynamic behaviour of two cointegrated I(1)-variables, say y_{1, t} and y_{2, t} with, probably, y_{2, t} a function of y_{1, t}. Note, the response must be a two–column matrix, where the first entry is the regressor, i.e, y_{1, t} above, and the regressand in the second colum. See Example 2 below.

The general specification of the ECM class described by this family function is

\Delta y_{1, t} |\Phi_{t - 1} = ~\phi_{0, 1} + \gamma_1 \widehat{z}_{t - k} + \sum_{i = 1}^K \phi_{1, i} \Delta y_{2, t - i} + \sum_{j = 1}^L \phi_{2, j} \Delta y_{1, t - j} + \varepsilon_{1, t},

\Delta y_{2, t} |\Phi_{t - 1}= ~\psi_{0, 1} + \gamma_2 \widehat{z}_{t - k} + \sum_{i = 1}^K \psi_{1, i} \Delta y_{1, t - i} + \sum_{j = 1}^L \psi_{2, j} \Delta y_{2, t - j} + \varepsilon_{2, t}.

Under the binormality assumption on the errors (\varepsilon_{1, t}, \varepsilon_{2, t})^T with covariance matrix \boldsymbol{\textrm{V}}, model above can be seen as a VGLM fitting linear models over the conditional means, \mu_{\Delta y_{1, t} } = E(\Delta y_{1, t} | \Phi_{t - 1}) and \mu_{\Delta y_{2, t} } = E(\Delta y_{2, t} | \Phi_{t - 1} ), producing

(\Delta y_{1, t} |\Phi_{t - 1} , \Delta y_{2, t} |\Phi_{t - 1} )^T \sim N_{2}(\mu_{\Delta y_{1, t}} , \mu_{\Delta y_{2, t}}, \boldsymbol{\textrm{V}})

The covariance matrix is assumed to have elements \sigma_1^2, \sigma_2^2, and \textrm{Cov}_{12}.

Hence, the parameter vector is

\boldsymbol{\theta} = (\phi_{0, 1}, \gamma_1, \phi_{1, i}, \phi_{2, j}, \psi_{0, 1}, \gamma_2, \psi_{1, i}, \psi_{2, j}, \sigma_1^2, \sigma_2^2, \textrm{Cov}_{12})^T,

for i = 1, \ldots, K and j = 1, \ldots, L.

The linear predictor is

\boldsymbol{\eta} = (\mu_{\Delta y_{1, t} }, \mu_{\Delta y_{2, t} }, {\color{blue}\texttt{loglink}}~\sigma_1^2, {\color{blue}\texttt{loglink}}~\sigma_2^2, \textrm{Cov}_{12})^T.

The estimated cointegrated vector, \boldsymbol{\widehat{\beta^{\star}}} = (1, -\boldsymbol{\widehat{\beta})}^T is obtained by linear regression depending upon resids.pattern, as follows:

1) y_{2, t} = \beta_0 + \beta_1 y_{1, t} + z_t, if resids.pattern = "intercept",

2) y_{2, t} = \beta_1 y_{1, t} + \beta_2 t + z_t, if resids.pattern = "trend",

3) y_{2, t} = \beta_1 y_{1, t} + z_t, if resids.pattern = "neither", or else,

4) y_{2, t} = \beta_0 + \beta_1 y_{1, t} + \beta_2 t + z_t, if resids.pattern = "both",

where \boldsymbol{\widehat{\beta}} = (\widehat{\beta_0}, \widehat{\beta_1}, \widehat{\beta_2})^T, and z_t assigns the error term.

Note, the estimated residuals, \widehat{z_t} are (internally) computed from any of the linear models 1) – 4) selected, and then lagged up to order alg.res, and embedded as explanatories in models \Delta y_{1, t} |\Phi_{t - 1} and \Delta y_{3, t} |\Phi_{t - 1} above. By default, \widehat{z}_{t - 1} are considered (as lag.res = 1), although it may be any lag \widehat{z}_{t - k}, for k > 0. Change this through argument lag.res.


An object of class "vglmff" (see vglmff-class) to be used by VGLM/VGAM modelling functions, e.g., vglm or vgam.


Reduced–Rank VGLMs (RR-VGLMs) can be utilized to aid the increasing number of parameters as K and L grows. See rrvglm.

By default, \sigma_1^2, \sigma_2^2 and \textrm{Cov}_{12} are intercept–only. Set argument zero accordingly to change this.

Package tsDyn also has routines to fit ECMs. However, the bivariate–ECM handled (similar to that one above) differs in their parametrization: tsDyn considers the current estimated residual, \widehat{z}_t instead of \widehat{z}_{t - 1} in models \Delta y_{1, t} |\Phi_{t - 1} and \Delta y_{2, t} |\Phi_{t - 1}.

See Example 3 below which compares ECMs fitted with VGAMextra and tsDyn.


Victor Miranda


Engle, R.F. and Granger C.W.J. (1987) Co-integration and error correction: Representation, estimation and testing. Econometrica, 55(2), 251–276.

Pfaff, B. (2011) Analysis of Integrated and Cointegrated Time Series with R. Seattle, Washington, USA: Springer.

See Also

MVNcov, rrvglm, CommonVGAMffArguments, Links, vglm.


## Example 1. Comparing the Engle -- Granger procedure carried oud by two procedures.
##            ECM.EngleGran() makes easier the fitting process.
## Here, we will use:
## A) The R code 4.2, in Chapter 4, Pfaff (2011).
##    This code 1) generates artificial data and 2) fits an ECM, following
##    the Engle --Granger procedure. 
## B) The ECM.EngleGran() family function to fit the same model assuming
##    bivariate normal innovations. 
## The downside in the R code 4.2 is the assumption of no--correlation among
## the errors. These are generated indenpendently.
## A)
## STEP 1. Set up the data (R code as in Pfaff (2011)).
nn <- 100
e1 <- rnorm(nn)   # Independent of e2
e2 <- rnorm(nn)
y1 <-  cumsum(e1)
y2 <- 0.6 * y1 + e2
lr.reg <- lm(y2 ~ y1)
error <- residuals(lr.reg)
error.lagged <- error[-c(nn - 1, nn)]
dy1 <- diff(y1)
dy2 <- diff(y2)
diff.dat <- data.frame(embed(cbind(dy1, dy2), 2))
colnames(diff.dat) <- c('dy1', 'dy2', 'dy1.1', 'dy2.1')

##  STEP 2. Fit the ECM model, using lm(), R code as in Pfaff (2011).
ecm.reg <- lm(dy2 ~ error.lagged + dy1.1 + dy2.1, data = diff.dat)


## B) Now, using ECM.EngleGran() and VGLMs, the steps at A) can be skipped. 
## Enter the I(1)--variables in the response vector only, putting down the
## the dependent variable from the I(1) set, i.e. y2, in the second column. <- data.frame(y1 = y1, y2 = y2)
fit.ECM <- vglm(cbind(y1, y2) ~ 1, ECM.EngleGran, data =, trace = TRUE)

## Check coefficients ##
coef(fit.ECM, matrix = TRUE)  ## Compare 'Diff2' with summary(ecm.reg)

head(depvar(fit.ECM))   # The estimated differences (first order)
constraints(fit.ECM, matrix = TRUE)

## Not run: 
### Example 2.  Here, we compare ECM.EngleGran() from VGAMextra with VECM() from
##              package "tsDyn" when fitting an ECM(1, 1). We will make use of
##              the argument 'ordtsDyn' so that the outcomes can be compared.

library("tsDyn")  # Need to be installed first.
fit.tsDyn1 <- with(, VECM(cbind(y2, y1), lag = 1, estim = "2OLS")) #  MODEL 1

### Fit same model using ECM.EngleGran(). NOTE: Set ordtsDyn = 1 !!          #  MODEL 2
fit.ECM.2 <- vglm(cbind(y1, y2) ~ 1, ECM.EngleGran(ecm.order = c(1, 1),
                  resids.pattern = "neither", ordtsDyn = 1),
                  data =, trace = TRUE)

coef.ECM.2 <- coef(fit.ECM.2, matrix = TRUE)
fit.tsDyn1$coefficients                      ## From pakage 'tsDyn'.
t(coef.ECM.2[, 1:2][c(2, 1, 4, 3), ][, 2:1]) ## FROM VGAMextra 

### Example 3. An ECM(2, 2), with residuals estimated by OLS, with NO intercept
###            and NO trend term. The data set is 'zeroyld', from package tsDyn.
###            ECM.EngleGran() and with VECM() willbe compared again.
data(zeroyld, package = "tsDyn")

# Fit a VECM with Engle-Granger 2OLS estimator: <- VECM(zeroyld, lag=2, estim = "2OLS") 

# For the same data, fit a VECM with ECM.EngleGran(), from VGAMextra.
# Set ordtsDyn = 1 for compatibility! 
fit.ECM.3 <- vglm(cbind(, ~ 1, ECM.EngleGran(ecm.order = c(2, 2),
                                  resids.pattern = "neither", ordtsDyn = 1),
                  data = zeroyld, trace = TRUE)
coef.ECM.3 <- coef(fit.ECM.3, matrix = TRUE)

#### Compare results$coefficients                               # From tsDyn
t(coef.ECM.3[, 1:2][c(2, 1, 5, 3, 6, 4 ),][, 2:1]) # FROM VGAMextra

## End(Not run)

VGAMextra documentation built on Nov. 2, 2023, 5:59 p.m.