Strange error message in CMLMT

I have written a simple code for the estimation of a VAR(2) model. The code is the following:

new;
cls;

library cmlmt;
#include cmlmt.sdf

data = loadd("E1");
T = rows(data);
K = cols(data);
lag_order = 2;

data = ln(data);
data_lag = packr(data~lag1(data));
data_diff = zeros(T - 1, K);

for i(1, K, 1);
data_diff[., i] = data_lag[., i] - data_lag[., i+K];
endfor;

A_in = -0.3195~0.1467~0.9592~0.1604~0.1151~0.93227|0.0441~-0.1520~0.2864~0.0502~0.0196~-0.0124|-0.0024~0.2249~-0.2642~0.0339~0.3550~0.0225;
A_in_mask = ones(K, K * lag_order);

mu_in = 0.0168|0.0196|0.0190;
Sigma_u_in = 0.0019~0.0001~0.0001|0.0001~0.0001~0.0001|0.0001~0.0001~0.0001;

struct PV p0;
p0 = pvCreate;
p0 = pvPackmi(p0, A_in, "A", A_in_mask, 1);
p0 = pvPacki(p0, mu_in, "mu", 2);
p0 = pvPacksi(p0, Sigma_u_in, "Sigma_u", 3);

struct DS d0;
d0 = dsCreate;
d0.DataMatrix = data_diff;

struct cmlmtControl c0;
c0 = cmlmtControlCreate;

c0.Title="Estimate VAR via maximum likelihood";
c0.NumObs = T-1;
c0.printIters = 1;
c0.Algorithm = 1;
c0.LineSearch = 1;
c0.CovParType = 1;

struct cmlmtResults out;
out = cmlmt(&VAR_ML_numerical, p0, d0, c0);
call cmlmtPrt(out);

proc VAR_ML_numerical(struct PV p, struct DS d, ind);
local A, mu, Sigma_u, Y, T, K, p, Y0, Y0_lag_demeaned, i, X, sum_ll;

struct modelResults mm;

A = pvUnpack(p, 1);
mu = pvUnpack(p, 2);
Sigma_u = pvUnpack(p, 3);

Y = d.Datamatrix;

T = rows(Y);
K = cols(Y);
p = lag_order;

Y0 = Y - mu';
Y0_lag_demeaned = zeros(T, K * p);

for i(1, p, 1);
Y0_lag_demeaned[i+1:T, K*(i-1)+1:K*i] = Y0[1:T-i, .];
endfor;

Y0_lag_demeaned = delrows(Y0_lag_demeaned, seqa(1, 1, p));
Y0 = delrows(Y0, seqa(1, 1, p));

Y0 = Y0';
X = Y0_lag_demeaned';

sum_ll = -0.5 * K * T * log(2 * pi) - 0.5 * T * ln(det(Sigma_u)) - 0.5 * sumc(diag((Y0 - A * X)' * ((Y0 - A * X) / Sigma_u)));

if ind[1];
mm.Function = sum_ll;
endif;

retp(mm);
endp;

When I run this, I get the following error message:

G0165 : Type mismatch or missing arguments Argument 1, found ??? (19), expected MATRIX 'Argument 1, found ??? (19), expected MATRIX ' [cmlmt.src, line 795]

What does this mean? I have never seen such an error message and I have no idea what the problem is. Is it that the objective function returns a scalar? That's why I defined c0.NumObs.

2 Answers



1



accepted

GAUSS is a big confused here.  With this declaration

proc VAR_ML_numerical(struct PV p, struct DS d, ind);

you have declared that p is a PV structure.  But then you also include p as a local matrix:

local A, mu, Sigma_u, Y, T, K, p, Y0, Y0_lag_demeaned, i, X, sum_ll;

CMLMT can't resolve those two specifications.  It has to be one or the other.

 



0



You are right. Oh boy, what a mistake! It would be nice if Gauss could distinguish between lowercase and uppercase variables, as Matlab can. And clearer error messages could also help...

But anyway, it's my fault of course.

Thanks a lot for your help!

Your Answer

2 Answers

1
accepted

GAUSS is a big confused here.  With this declaration

proc VAR_ML_numerical(struct PV p, struct DS d, ind);

you have declared that p is a PV structure.  But then you also include p as a local matrix:

local A, mu, Sigma_u, Y, T, K, p, Y0, Y0_lag_demeaned, i, X, sum_ll;

CMLMT can't resolve those two specifications.  It has to be one or the other.

 

0

You are right. Oh boy, what a mistake! It would be nice if Gauss could distinguish between lowercase and uppercase variables, as Matlab can. And clearer error messages could also help...

But anyway, it's my fault of course.

Thanks a lot for your help!


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy