Problem with vector autoregressive model (vgxvarx) - "Covariance is not positive-definite."

12 views (last 30 days)
Hi.
I have a dataset of 27 different variables measured during the same time period with the same lengths that I am trying to create a vector autoregressive model of using the method shown in the webinar Long Term Energy Forecasting with Econometrics in MATLAB which is basically:
Y=data; %10000x27 matrix of data
nAR = 12; % Define number of lags
Spec = vgxset('n', numel(YSeries), 'Constant', true, 'nAR', nAR, 'Series', YSeries);
Spec = vgxvarx(Spec, Y);
If I try running this with only two of the vectors Y(:,1:2) it works but the model obviously isn’t very good. When I start introducing more vectors to the model for example Y(:,1:10) I always get the error:
Error using mvregress (line 452)
Covariance is not positive-definite.
And I am unable to build the model.
What am I doing wrong here? In the webinar example he has many input vectors and the code never complains...
Thanks.

Accepted Answer

Hang Qian
Hang Qian on 28 Jul 2015
Hi Peta,
The codes appear syntactically correct. You might want to check the correlations of your 27 variables and the constant term, making sure they are not perfectly correlated. You may also consider a more parsimonious model, as 12 lags would imply more than 8000 unknown parameters in the model. There is a chance that numerical problems make the covariance matrix non-positive definite, though they are positive definite in theory. Also, most users would partition the data and set the name-value pair “Y0” as the initial observations, and Y for the remaining sample. This will yield the OLS results. The default “Y0” are padded by zeros.
- Hang Qian
  2 Comments
Peta
Peta on 28 Jul 2015
I’ve managed to get it working now, the problem occurred when most of my variables had values varying around 0.5-1.5 and others were varying around 100. By dividing the larger variables by 100 and thereby bringing them down to the same scale as the rest before constructing the model I don’t get the error. After the forecast I then multiply by 100 again to get the correct scale.
And also the VAR functions doesn’t appear to like working with single numbers, not only is it slower but it produces errors and warnings that I don’t receive when working with doubles. Which is a bit strange. Since large VAR models are very memory intensive it would be preferable for me to work in singles.
Hang Qian
Hang Qian on 12 Aug 2015
Thank you very much for your suggestions on the single-precision algebra for the VAR model!

Sign in to comment.

More Answers (1)

Maisa Melo
Maisa Melo on 28 Aug 2018
Hi Peta,
I need implement a code using vgxvarx at Matlab, but I'm not know exacly how is the input data. I'm trying reproduce your code, but in your code there is no the valur of YSeries. I would like know your YSeries for I reproduce your code.
Best regard.
Maisa

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!