# How to test for serial correlation and ARCH effect in R package tsDyn?

I recently started playing around with the tsDyn package for R and successfully used it to estimate a bunch of VEC models and print their impulse responses (IRF) and error variance decompositions (FEVD). While I really like its intuitive and straightforward functions, one thing I have not been able to figure out is how to conduct diagnostic tests for a VEC model in tsDyn, specifically tests for serial correlation and ARCH effects?

I tried to convert a tsDyn-generated VEC model to a VAR in levels using the vec2var() function to apply the serial.test() and arch.test() functions from the vars package, but this failed, presumably because vec2var() doesn't know how to handle classes produced by tsDyn. Since I am unsure whether this is the correct approach in the first place, I was hoping someone here may be able to give advice on the issue.

Here is what I did after loading library(tsDyn) and library(vars):

data(barry)
ve <- VECM(barry, lag=1, estim="ML")
serial.test(ve)
Error in serial.test(ve) :
Please provide an object of class 'varest', generated by 'var()', or an object of
class 'vec2var' generated by 'vec2var()'.
vec2var(ve)
Error in vec2var(ve) :
Please, provide object of class 'ca.jo' as 'z'.
In if (!(class(z) == "ca.jo")) { :
the condition has length > 1 and only the first element will be used

• You could include tags like autocorrelation and garch instead of cointegration; they might be more relevant. – Richard Hardy Feb 17 '15 at 12:36
• This is Mat, I'm working on that package. Give me 1-2 days to answer as quite busy now, but in a nutshell you are right using vec2var() is the way to go, I'll check why/what it doesn't work. If oyu want in the meanwhile to provide small reproducible code, go ahead! – Matifou Feb 18 '15 at 3:55
• Thanks for the suggestion, Richard, and thank you for looking into this personally, Mat. From what I understand, tsDyn's irf() and fevd() functions internally also use vec2var() in some way, I just wasn't able to figure out what they do differently as I don't have much experience digging into the code of contributed packages. – dreamon Feb 18 '15 at 12:04

You need to convert yourself the VECM into a class recognised by urca, using the function vec2var.tsDyn which is however (currently) not exported, so you need the unusual construction: tsDyn:::vec2var.tsDyn. And then can apply (most of) the vars/urca functions:

library(tsDyn);library(vars)
data(barry)
ve <- VECM(barry, lag=1, estim="ML")
ve_urca <- tsDyn:::vec2var.tsDyn(ve)
serial.test(ve_urca)


Gives you (in this case) the same result than using ca.jo directly:

ve_ur <- ca.jo(barry, K=2, spec="transitory")
var_ur <- vec2var(ve_ur)
serial.test(var_ur)


Best

• Works like a charm. Exactly what I needed. Thanks, Mat! – dreamon Feb 21 '15 at 8:09