Portmanteau tests and degrees of freedom

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Portmanteau tests and degrees of freedom

Postby sean123 » Tue Jul 10, 2012 5:33 am

Hi,

I'm working with some VAR models and I've come to a stage where I need to impose some restrictions, so I make it into a system and make my changes. The issue is when testing for autocorrelation, since the degrees of freedom differ from when using the same test in a VAR model. I tried to find some logic in how the degrees of freedom are calculated, but without success. I must be missing something but I cannot understand what.

In a bivariate VAR(4) the degrees of freedom is according to the User guide: k^2(h-p)=2^2(h-4), which for h=5 then should be equal to 4 (2^2(5-4)). The test says 7. I played around a little and I can't find any mathematical logic in the following degrees of freedom (for all h=5 and p=4):

Code: Select all

k=2, test says 7 df k=3, test says 16 df k=4, test says 29 df k=5, test says 46 df k=6, test says 67 df k=7, test says 92 df
These dfs do not correspond to the ones they "should" be according k^2(h-p), which for the first valid lag should simply be k^2 since the first valid lag is by definition (h-p)=1. When h increases, the degrees of freedom increase with k^2 for each h, so at least there I can make some sense of it. But the confusion continues when looking at the exact (or so I thought) procedure in a System object, where the degrees of freedom for an unrestricted seven-variable VAR(4) for h=1 is 49. Here, the degrees of freedom seem to be calculated as k^2(h-p) where p is always 0.

If anyone can help shed some light on this I would be very grateful.

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Re: Portmanteau tests and degrees of freedom

Postby sean123 » Tue Jul 10, 2012 5:46 am

A related question: Is there a reason why the Autocorrelation LM test is not available in the System procedure? I was thinking of trying to write a program which would calculate it for me, but the fact that it isn't already implemented could be a sign that it isn't possible or very hard to do so...

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Portmanteau tests and degrees of freedom

Postby EViews Gareth » Tue Jul 10, 2012 9:24 am

Looks like there is a bug with VARs calculated by command/program, where the dof for the test is being incorrectly calculated. We'll get a fix up soon.

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Re: Portmanteau tests and degrees of freedom

Postby sean123 » Tue Jul 10, 2012 11:19 pm

Thanks for the reply. Sounds reasonable that there's something which isn't working properly here. Would you happen to know the reason for the exclusion of the LM test in a System object, and if it would be possible for me to construct it (assuming my own skills won't be an issue) or if there are any limitations to the test itself in this environment?

Edit: I've had a brief look at the LM test now trying to reproduce the LM stats reported by Eviews manually. The statistic is: LM(s)=Delta*log(abs(C_R)/abs(C_UR)) and it is (asymptotically, I think) chi square distributed with s*k^2 dof under the null. Delta is a straight-forward calculation of, well, something, but that's not my problem (it's just regular scalar algebra). How exactly would I perform the C_R/C_UR division in Eviews? These are covariance matrices for the equations without lagged error terms (C_R) and and with lagged error terms (C_UR). I'm not very familiar yet with matrix algebra as I'm taking that class this fall. What value of the matrix would I be looking for in this situation and how would I go about extracting it using an Eviews command?

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Re: Portmanteau tests and degrees of freedom

Postby sean123 » Wed Jul 11, 2012 11:56 pm

The reason I didn't get a single value from the matrix was that I interpreted the notation for the determinants of the matrices as absolute values... After that was pointed out to me I've put together a code for the test following the procedure in Johansen (1995, p. 22). Essentially, as I understand it, the statistic is simply the log of the determinant of the restricted residual covariance matrix divided by the determinant of the unrestriced residual covariance matrix and then that multiplied by some sort of "correction" for series lengths, lags and parameters. I'm not getting the correct results, but as has happened before it's probably just due to some sort of obvious and simple mistake. If you'd have a look at the code below and see if there's something funny going on somewhere that would be great!

Code: Select all

create q 1990q1 1994Q4 'create workfile and variables series x = nrnd series y = nrnd '(T-pk-m-p-0.5) !T=20 'Number of observations !m=2 'Number of intercepts/dummies/trends/etc(?) !p=2 'Number of endogenous variables !k=2 'Number of lags !s=1 'Lag being tested scalar cn=!T-!p*!k-!m-!p-0.5 'create a scalar which is the first part of the LM(s) equation var var.ls 1 2 x y @ c 'estimate the bivariate var model var.makeresids resid_x resid_y 'create the residual series resid_x(1)=0 'set the two first NAs to zero resid_x(2)=0 resid_y(1)=0 resid_y(2)=0 system sys_res 'restricted model sys_res.append resid_x=c(1)*x(-1) + c(2)*x(-2) + c(3)*y(-1) + c(4)*y(-2) + c(5) sys_res.append resid_y=c(6)*x(-1) + c(7)*x(-2) + c(8)*y(-1) + c(9)*y(-2) + c(10) sys_res.ls freeze(residcov_res) sys_res.residcov 'get the residual covariance matrix matrix(2,2) res 'create matrix and fill it res(1,1)=residcov_res(3,2) res(2,1)=residcov_res(4,2) res(1,2)=residcov_res(3,3) res(2,2)=residcov_res(4,3) d residcov_res system sys_aux auxiliary model sys_aux.append resid_x=c(1)*x(-1) + c(2)*x(-2) + c(3)*y(-1) + c(4)*y(-2) + c(5) + c(11)*resid_x(-1) + c(12)*resid_y(-1) 'same as the restriced model but with lagged residuals sys_aux.append resid_y=c(6)*x(-1) + c(7)*x(-2) + c(8)*y(-1) + c(9)*y(-2) + c(10) + c(13)*resid_x(-1) + c(14)*resid_y(-1) sys_aux.ls 'estimate the system and save the residual covariance matrix freeze(residcov_sys) sys_aux.residcov matrix(2,2) unres unres(1,1)=residcov_sys(3,2) unres(2,1)=residcov_sys(4,2) unres(1,2)=residcov_sys(3,3) unres(2,2)=residcov_sys(4,3) d residcov_sys scalar LMtest=cn*log(@det(res)/@det(unres)) 'calculate the LM statistic show LMtest show var.arlm(!s) 'show the VAR object's LM statistic for comparison purposes
Edit: Code updated and some things corrected. I get values close to what the built-in test in the VAR object produces, but not exactly the same.

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Re: Portmanteau tests and degrees of freedom

Postby sean123 » Thu Jul 12, 2012 7:59 am

After a lot of work and trial and error me and my colleague got it working! We also extended it to produce the version of the Autocorrelation LM stat which tests autocorrelation up to lag h, and not at lag h, which Eviews does. We ended up with a tiny problem of some practical importance: Is there a way to get "all" decimals from the residual covariance matrix? Freezing it and then storing it in a matrix using a program (and not copy/paste) reduces the number of decimals and it affects the result - the statistic went from 6.37 to 5.77 because of this. Any idea? The ideal thing would be to be able to save the residual covariance matrix directly, i.e. something along the lines of: var.residcov residcov_matrix. But anything that still keeps all of the decimals would be nice.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Portmanteau tests and degrees of freedom

Postby EViews Gareth » Thu Jul 12, 2012 8:32 am

var.makeresids, then find the covariance matrix. Any time you freeze something you're going to lose accuracy.

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Re: Portmanteau tests and degrees of freedom

Postby sean123 » Wed Jul 25, 2012 1:45 am

Thank you! I didn't know that about the freeze function, but I guess it makes sense. Obtaining the covariance matrix "manually" is of course a very reasonable way to go about solving that problem...


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 2 guests