matrix is singular

Hi Mr Ron Schoenberg

Thank you for answering my question. Unfortunately again errors which already happened, still remain and I can not solve it. if it is possible, I send you code and data. and guide me how I solve this dilemma

I write code here but for data please send me your Email address.

// Libraries
library cmlmt,pgraph;

// Data

x=xlsreadm("datafilename","a1:b100",1,0);

y=x-meanc(x)';

n=rows(y);

k=cols(y);

struct DS d0;

d0=dsCreate;

d0.DataMatrix=y;

// Declarations

varred=vcx(y);

epsilon=y';

avec=zeros(k,n);

lnvar=zeros(k,n);

lnvar[.,1]=ln(diag(varred));

var=diagrv(eye(k),exp(lnvar[.,1]));

ind=1|1|1;

// Parameters

struct PV p;

a12=0;

b12=0;

b122=0;

b123=0;

a21=0;

b21=0;

b212=0;

b213=0;

A=1~avec[1,1]|avec[2,1]~1;

g=eye(k)*0.95;

d=eye(k)*0.15;

f=eye(k)*(-0.09);

c=lnvar[.,1].*(1-diag(g));

uncs=A*varred*A';

rho=uncs[1,2]/sqrt(uncs[1,1]*uncs[2,2]);

p=pvPack(pvCreate,a12,"a12");

p=pvPack(p,b12,"b12");

p=pvPack(p,b122,"b122");

p=pvPack(p,b123,"b123");

p=pvPack(p,a21,"a21");

p=pvPack(p,b21,"b21");

p=pvPack(p,b212,"b212");

p=pvPack(p,b213,"b213");

p=pvPack(p,c,"c");

p=pvPack(p,g,"g");

p=pvPack(p,d,"d");

p=pvPack(p,f,"f");

p=pvPack(p,rho,"rho");

// Algorithm settings

struct cmlmtControl c0;

c0=cmlmtControlCreate;

c0.Algorithm=4;

c0.LineSearch=4;

c0.CovParType=2;

c0.printIters=1;

c0.DirTol=0.0001;

//c0.TrustRadius=0.001;

//c0.Switch=1|10000000|0;

//c0.Switch={3 1, 0.1 0.1, 1 1, .001 .001};

// Start likelihood procedure

proc likproc(struct PV p, struct DS d0, ind);

// Declarations

local i,llik,a12,b12,a21,b21,c,g,d,f,A,trans,b122,b123,b212,b213,rho;

llik=zeros(n,1);

A=1~avec[1,1]|avec[2,1]~1;

a12=pvUnpack(p,"a12");

b12=pvUnpack(p,"b12");

b122=pvUnpack(p,"b122");

b123=pvUnpack(p,"b123");

a21=pvUnpack(p,"a21");

b21=pvUnpack(p,"b21");

b212=pvUnpack(p,"b212");

b213=pvUnpack(p,"b213");

c=pvUnpack(p,"c");

g=pvUnpack(p,"g");

d=pvUnpack(p,"d");

f=pvUnpack(p,"f");

rho=pvUnpack(p,"rho");

y=d0.DataMatrix;

// Loop of likelihood for each observation

i=2;

do while i<=n;

// EGARCH for structural conditional variance process

lnvar[.,i]=c+g*lnvar[.,i-1]+d*(abs(epsilon[.,i-1]./sqrt(exp(lnvar[.,i-1])))-sqrt(2/pi))+f*(epsilon[.,i-1]./sqrt(exp(lnvar[.,i-1])));

// Transition variable = demeaned sqrt-variance

trans=sqrt(exp(lnvar[.,i]));
//-sqrt(exp(c./(1-diag(g))));

// Linear Variance Spillover vs. Taylor vs. Smooth Transition

avec[.,i]=a12+b12*trans[2]|a21+b21*trans[1];

//avec[.,i]=a12+b12*trans[2]+b122*trans[2]^2+b123*trans[2]^3|a21+b21*trans[1]+b212*trans[1]^2+b213*trans[1]^3;

// Structural coefficients matrix at time i

A=1~avec[1,i]|avec[2,i]~1;

// Structural Shocks

epsilon[.,i]=A*y[i,.]';

// Log-Likelihood

var=(1~rho*sqrt(exp(lnvar[1,i]+lnvar[2,i]))/exp(lnvar[2,i])|rho*sqrt(exp(lnvar[1,i]+lnvar[2,i]))/exp(lnvar[1,i])~1)*diagrv(eye(k),exp(lnvar[.,i]));

llik[i]=-0.5*(k*ln(2*pi)+ln(det(var))-2*ln(det(A))+y[i,.]*(A'*inv(var)*A)*y[i,.]');

i=i+1;

endo;

struct modelResults mm;

mm.Function=llik;

retp(mm);

endp;

// Inequality restrictions

proc ineqp(struct PV p, struct DS d0);

local g,d,f;

g=pvUnpack(p,"g");

d=pvUnpack(p,"d");

f=pvUnpack(p,"f");

retp(1-g[1,1]|1-g[2,2]|d[1,1]|d[2,2]);

endp;

c0.IneqProc=&ineqp;

// Equality restrictions ... restrict spillover from 1 to 2 (1 to source) to zero

proc eqp(struct PV p, struct DS d0);

local g,d,f,b12,b122,b123,b21,b212,b213;

b21=pvUnpack(p,"b21");

b212=pvUnpack(p,"b212");

b213=pvUnpack(p,"b213");

b12=pvUnpack(p,"b12");

b122=pvUnpack(p,"b122");

b123=pvUnpack(p,"b123");

g=pvUnpack(p,"g");

d=pvUnpack(p,"d");

f=pvUnpack(p,"f");

retp(b212|b213|b122|b123); // adjust to desired rstrictions

endp;

//c0.eqProc=&eqp; // uncomment for activating equality restrictions

// Output

struct cmlmtResults res;

res=cmlmt(&likproc,p,d0,c0);

cmlmtprt(res);

thank you so much

6 Answers



0



accepted

I commented out the line of code where the Hessian was failing to invert.  That line of code computes the covariance matrix of the inequality Lagrangean, which doesn't matter for the solution.  The resulting solution is QML covariance matrix as selected in the command file.  The QML requires the Hessian as well, but the Hessian is negative definite so it uses a generalized inverse instead and thus standard errors are produced for the solution.  The solution is presented below.  I'd be interested in knowing if it looks anything like the published solution because it appears very problematic to me.  The correlation matrix computed from the QML covariance matrix shows four parameters 3,4,7, and 8 are perfectly correlated.   This indicates to me that they are really all the same parameter.  They really should be constrained to be equal to get a legitimate solution.

 

 

===============================================================================
CMLMT Version 3.0.2                                       8/25/2017  10:18 am
===============================================================================

return code =    0
normal convergence

Log-likelihood        -529.976
Number of cases     100

Covariance of the parameters computed by the following method:
QML covariance matrix
Parameters    Estimates     Std. err.  Est./s.e.  Prob.    Gradient
---------------------------------------------------------------------
a12[1,1]     0.1011        0.0907       1.114   0.2651     -2.3130
b12[1,1]    -0.0123        0.0108      -1.131   0.2579    -37.2818
b122[1,1]   -0.0034        3.4714      -0.001   0.9992      0.0000
b123[1,1]   -0.0034        3.4714      -0.001   0.9992      0.0000
a21[1,1]    -0.0897        2.5596      -0.035   0.9720     -0.4346
b21[1,1]    -0.3188        0.6852      -0.465   0.6418     -3.8194
b212[1,1]   -0.0034        3.4714      -0.001   0.9992      0.0000
b213[1,1]   -0.0034        3.4714      -0.001   0.9992      0.0000
c[1,1]      -0.1860        2.7314      -0.068   0.9457     -3.8770
c[2,1]       0.0786        0.2444       0.322   0.7478     -5.6544
g[1,1]       0.8101        0.1431       5.661   0.0000     -5.1150
g[1,2]       0.0655        0.6122       0.107   0.9148     -5.5714
g[2,1]       0.0409        0.0911       0.449   0.6536     -1.6202
g[2,2]       0.9750        0.0651      14.967   0.0000    -14.3940
d[1,1]       0.5139        0.3918       1.312   0.1897      4.3009
d[1,2]       0.1182        0.1938       0.610   0.5420     -1.0141
d[2,1]      -0.1469        0.2349      -0.625   0.5318     -2.8273
d[2,2]       0.0000             .           .   0.0000    -18.9045
f[1,1]       0.2931        0.1568       1.869   0.0617      1.5505
f[1,2]      -0.2537        0.1270      -1.998   0.0457      2.3370
f[2,1]      -0.0472        0.1176      -0.401   0.6881      3.2045
f[2,2]      -0.0325        0.0755      -0.431   0.6663      1.6701
rho[1,1]    -0.2878        0.4239      -0.679   0.4971     -2.1821

Correlation matrix of the parameters
1      -0.92298537       0.56603741       0.56603741       0.49976339       -0.2817871       0.56603741       0.56603741       0.54262848      -0.51355875       0.55282309      -0.55506978       -0.5775175       0.56863552       0.39250194       0.36993703       0.44379833                .      -0.08836436       0.32862714       0.43741465     -0.092214762        0.1828932
-0.92298537                1      -0.58631649      -0.58631649      -0.58685053       0.57701984      -0.58631649      -0.58631649      -0.61314406       0.59968766      -0.73080058       0.62414838       0.75043645      -0.66209355      -0.56411437      -0.39129051      -0.51434875                .       0.20205887      -0.18773819      -0.59609973       0.15875724       0.12816736
0.56603741      -0.58631649                1                1       0.94298277      -0.49245765                1                1       0.96369252      -0.59569304       0.68523044      -0.96828846      -0.76920802       0.67991546       0.47730382       0.59629686       0.91299956                .      0.074852873       0.42312916       0.77367586        -0.677527       0.35419964
0.56603741      -0.58631649                1                1       0.94298277      -0.49245765                1                1       0.96369252      -0.59569304       0.68523044      -0.96828846      -0.76920802       0.67991546       0.47730382       0.59629686       0.91299956                .      0.074852873       0.42312916       0.77367586        -0.677527       0.35419964
0.49976339      -0.58685053       0.94298277       0.94298277                1      -0.63695509       0.94298277       0.94298277       0.99007521      -0.71118711       0.67764534       -0.9887625      -0.79494842       0.76797468       0.67822637       0.57738533       0.90527226                .       0.22771361       0.41075624       0.77893453      -0.73801233       0.22368734
-0.2817871       0.57701984      -0.49245765      -0.49245765      -0.63695509                1      -0.49245765      -0.49245765      -0.61679519        0.4682442      -0.72142402       0.61605814       0.70672957      -0.52019889       -0.7045325      -0.28081664      -0.50081276                .       0.12169461       0.13251585      -0.61653611       0.35200912       0.58165323
0.56603741      -0.58631649                1                1       0.94298277      -0.49245765                1                1       0.96369252      -0.59569304       0.68523044      -0.96828846      -0.76920802       0.67991546       0.47730382       0.59629686       0.91299956                .      0.074852873       0.42312916       0.77367586        -0.677527       0.35419964
0.56603741      -0.58631649                1                1       0.94298277      -0.49245765                1                1       0.96369252      -0.59569304       0.68523044      -0.96828846      -0.76920802       0.67991546       0.47730382       0.59629686       0.91299956                .      0.074852873       0.42312916       0.77367586        -0.677527       0.35419964
0.54262848      -0.61314406       0.96369252       0.96369252       0.99007521      -0.61679519       0.96369252       0.96369252                1      -0.69518457       0.69351334      -0.99949326      -0.81803776       0.76283204       0.64969662       0.54468375       0.91436867                .       0.20081677       0.36964106       0.80336629      -0.69714204       0.23568045
-0.51355875       0.59968766      -0.59569304      -0.59569304      -0.71118711        0.4682442      -0.59569304      -0.59569304      -0.69518457                1      -0.37883157       0.68720386       0.76418601      -0.98846887      -0.65987501      -0.28032409      -0.60101943                .      -0.27983584      -0.23460797      -0.74829159       0.23217505     -0.093587229
0.55282309      -0.73080058       0.68523044       0.68523044       0.67764534      -0.72142402       0.68523044       0.68523044       0.69351334      -0.37883157                1      -0.70758547      -0.78075396       0.47723663       0.55757131       0.40593665       0.59433394                .      -0.36969482       0.19133685       0.64600837      -0.46870284      -0.22349628
-0.55506978       0.62414838      -0.96828846      -0.96828846       -0.9887625       0.61605814      -0.96828846      -0.96828846      -0.99949326       0.68720386      -0.70758547                1       0.82026576      -0.75768174      -0.64354326      -0.55157013      -0.91438298                .      -0.17874208      -0.37564018      -0.80303346       0.69630147       -0.2360292
-0.5775175       0.75043645      -0.76920802      -0.76920802      -0.79494842       0.70672957      -0.76920802      -0.76920802      -0.81803776       0.76418601      -0.78075396       0.82026576                1      -0.84471839      -0.66289954      -0.38992378      -0.76572317                .      0.088305937     -0.089118454      -0.92818155        0.4405828       0.10916989
0.56863552      -0.66209355       0.67991546       0.67991546       0.76797468      -0.52019889       0.67991546       0.67991546       0.76283204      -0.98846887       0.47723663      -0.75768174      -0.84471839                1       0.67441573       0.33065012       0.67348679                .        0.2118192       0.23300585       0.82027154       -0.2893655      0.089550503
0.39250194      -0.56411437       0.47730382       0.47730382       0.67822637       -0.7045325       0.47730382       0.47730382       0.64969662      -0.65987501       0.55757131      -0.64354326      -0.66289954       0.67441573                1       0.21763774       0.40884423                .       0.38102619       0.21840014       0.47904365       -0.4219888      -0.19510113
0.36993703      -0.39129051       0.59629686       0.59629686       0.57738533      -0.28081664       0.59629686       0.59629686       0.54468375      -0.28032409       0.40593665      -0.55157013      -0.38992378       0.33065012       0.21763774                1       0.60692559                .     0.0086365431       0.31842696       0.36883485      -0.44590025       0.21271789
0.44379833      -0.51434875       0.91299956       0.91299956       0.90527226      -0.50081276       0.91299956       0.91299956       0.91436867      -0.60101943       0.59433394      -0.91438298      -0.76572317       0.67348679       0.40884423       0.60692559                1                .      0.059703718       0.23691005       0.84712439      -0.71890553       0.28547473
.                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .                .
-0.08836436       0.20205887      0.074852873      0.074852873       0.22771361       0.12169461      0.074852873      0.074852873       0.20081677      -0.27983584      -0.36969482      -0.17874208      0.088305937        0.2118192       0.38102619     0.0086365431      0.059703718                .                1       0.32796069      -0.13413348      -0.23398394       0.40533553
0.32862714      -0.18773819       0.42312916       0.42312916       0.41075624       0.13251585       0.42312916       0.42312916       0.36964106      -0.23460797       0.19133685      -0.37564018     -0.089118454       0.23300585       0.21840014       0.31842696       0.23691005                .       0.32796069                1     0.0044772014      -0.50091465       0.58437021
0.43741465      -0.59609973       0.77367586       0.77367586       0.77893453      -0.61653611       0.77367586       0.77367586       0.80336629      -0.74829159       0.64600837      -0.80303346      -0.92818155       0.82027154       0.47904365       0.36883485       0.84712439                .      -0.13413348     0.0044772014                1      -0.44756197      -0.02207378
-0.092214762       0.15875724        -0.677527        -0.677527      -0.73801233       0.35200912        -0.677527        -0.677527      -0.69714204       0.23217505      -0.46870284       0.69630147        0.4405828       -0.2893655       -0.4219888      -0.44590025      -0.71890553                .      -0.23398394      -0.50091465      -0.44756197                1      -0.32857061
0.1828932       0.12816736       0.35419964       0.35419964       0.22368734       0.58165323       0.35419964       0.35419964       0.23568045     -0.093587229      -0.22349628       -0.2360292       0.10916989      0.089550503      -0.19510113       0.21271789       0.28547473                .       0.40533553       0.58437021      -0.02207378      -0.32857061                1

 

 

Wald Confidence Limits

0.95 confidence limits
Parameters    Estimates     Lower Limit   Upper Limit   Gradient
----------------------------------------------------------------------
a12[1,1]     0.1011       -0.0796        0.2818       -2.3130
b12[1,1]    -0.0123       -0.0338        0.0093      -37.2818
b122[1,1]   -0.0034       -6.9158        6.9091        0.0000
b123[1,1]   -0.0034       -6.9158        6.9091        0.0000
a21[1,1]    -0.0897       -5.1866        5.0071       -0.4346
b21[1,1]    -0.3188       -1.6832        1.0457       -3.8194
b212[1,1]   -0.0034       -6.9158        6.9091        0.0000
b213[1,1]   -0.0034       -6.9158        6.9091        0.0000
c[1,1]      -0.1860       -5.6248        5.2528       -3.8770
c[2,1]       0.0786       -0.4081        0.5653       -5.6544
g[1,1]       0.8101        0.5252        1.0951       -5.1150
g[1,2]       0.0655       -1.1535        1.2845       -5.5714
g[2,1]       0.0409       -0.1406        0.2224       -1.6202
g[2,2]       0.9750        0.8453        1.1047      -14.3940
d[1,1]       0.5139       -0.2663        1.2940        4.3009
d[1,2]       0.1182       -0.2677        0.5040       -1.0141
d[2,1]      -0.1469       -0.6146        0.3208       -2.8273
d[2,2]       0.0000             .             .      -18.9045
f[1,1]       0.2931       -0.0192        0.6054        1.5505
f[1,2]      -0.2537       -0.5066       -0.0008        2.3370
f[2,1]      -0.0472       -0.2815        0.1870        3.2045
f[2,2]      -0.0325       -0.1828        0.1177        1.6701
rho[1,1]    -0.2878       -1.1319        0.5562       -2.1821

Number of iterations    31
Minutes to convergence     0.13173

 



0



Hi Dr RonSchoenberg

I am very appreciated of you. It is interesting to me that you can obtain solution without any error. I have tried several times but Always encountered an error: the matrix is singular. Mr. Ron Schonberg I am the beginner of gauss And If it is possible to guide me more. you said: commented out the line of code where the Hessian was failing to invert. That line of code computes the covariance matrix of the inequality Lagrangean, which doesn't matter for the solution.
please tell me which line of code I have to commented out ( I mean that the code which I sent you or code in cmlmt? then which line?)
parameters 3,4,7,8 can not be the same and it is a confusing for me here but, they just can be restricted to zero when a direction of spillover is unidirectional for example spillover from market 1 to market 2, not vice Versa.
and one more things, data that I sent you is belong to returns of the index of USA, Iran and Germany stock market then data that was used in the original paper is different.
if you want I can explain more about the steps are taken in article and code then sent to you by email.
this work is vital for me.
best regard
behrouz



0



I don't know what version of CMLMT you have so I'm not able to specify a line in the code because it could be very different from mine.  The line of code to comment out is the line where GAUSS stops and tells you the matrix can't be inverted.  Thus, run your command file.  When it stops with an error message, it will tell you the line it stopped on.  Click on that line and the file will be brought up and you can comment out that line by putting // in the first two columns of that line.



0



And I want to emphasize, it is not possible to estimate parameters 3,4,7 and 8 separately.  It appears to me that you must either constrain them to be equal, or remove, probably at least two of them, from the model.  Setting them to zero might work too.  The results, however, are clear. There is not enough information in the data to identify, that is, estimate, those four parameters.



0



the version of cmlmt is :CMLMT Version 1.0.5



0



Hi, Dr. Schoenberg

yes you are right. putting maxiters to some limited iteration can not be useful.

but  I sent you a pic that shows where the program has been stopped. you said put // in the first two columns of that line. I want to know, this line is equal as same as what you said?

out1.lagr.eqcov = inv(eqc*inv(h)*eqc');

If you answer for this, the problem is solved.

 

 

Sorry for taking your precious time.

 

 

 

Your Answer


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 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy