laubach and williams code

hi everyone

I'm using laubach and williams code in order to estimate the natural rate of interest. I'm a beginner in gauss.

i'm trying to inverse my matrix . But it doesn't work.

i have this error "matrix not positive define"

when i print my matrix, i see that my matrix is full of zero

What can i do?

 

Thank you

8 Answers



0



The error "matrix not positive definite" happens when you are trying to invert a matrix using the function, invpd. The invpd function requires that the input matrix is positive definite. Most of the time it is used to invert a moment matrix (X'X) which should be positive definite unless there is some linear dependence in the variables.

When you say your matrix is full of zeros, do you mean that it is entirely zeros? Or that it just has quite a few of them? You might be having a problem loading your data correctly. Can you post a link to the code so we can offer more help?

aptech

1,773


0



Thank you for answering me.

I mean when i use the function "print" to see my matrix. I see that it's entirely zeros



0



If your matrix is entirely zeros, then it is certainly singular. Does the program simulate data, or is this data that you loaded from a file?

aptech

1,773


0



thank you again

well,

here is my code

/* ----------------------------------------------------------------------
rstar_s1.g: First-stage estimation of the model without hours in
Laubach-Williams, FEDS 2001-56. Last modified 09/03/02.
---------------------------------------------------------------------- */

library optmum;
optset;
output file = /mq/home/m1hxl00/work/nri/nrv2/n2v1.out reset;
format /rd 8,4;

load dat[218,7] = /mq/home/m1hxl00/work/nri/nrv2/nr2_0902.dat;
dat[.,5] = dat[.,5]-dat[.,3]; /* Relative oil price inflation */
dat[.,6] = dat[.,6]-dat[.,3]; /* Relative import price inflation */
dat[.,7] = dat[.,7]-dat[.,4]; /* Ex ante real rate */
mv = miss(0,0);

nt = 166; /* Sample 61:1 - 02:2 */
nar = 7; /* Number of regressors */
nsv = 3; /* Number of state variables */
nst = nt; /* Startup periods for filter */
niter = 1000; /* Number of draws for generating error bands */
seed1 = 40;
indx = 0; /* Index for initialisation of P(0|0) during MC simulation */

/* Setting up system matrices:
a1 filtered state a(t|t)
a2 smoothed state a(t|T)
p1s covariance matrix of filtered state
p2s covariance matrix of smoothed state
b coefficients on explanatory variables in measurement equation
xr regressor matrix in measurement equation
z coefficients on state vector in measurement equation
h covariance matrix of measurement equation error
t transition matrix in transition equation
q covariance matrix of transition equation error */

a1 = zeros(nt+1,nsv);
a2 = zeros(nt+1,nsv);
p1s = zeros(nst*nsv,nsv);
p2s = zeros(nst*nsv,nsv);
b = zeros(2,nar);
z = zeros(2,nsv);
h = zeros(2,2);
t = zeros(nsv,nsv);
t[1:2,1] = ones(2,1);
t[3,2] = 1;
q = zeros(nsv,nsv);

/* Computing starting values for parameters */

/* Potential XBO proxied by segmented trend 60:1 to 00:4 */
xr = ones(nt+4,1)~seqa(1,1,nt+4);
xr = xr~(zeros(56,1)|seqa(1,1,nt-52))~(zeros(142,1)|seqa(1,1,nt-138));
xi = invpd(xr'xr);
bpot = xi*xr'dat[49:nt+52,1];
gpot = xr*bpot;
gap = 100*(dat[49:nt+52,1]-xr*bpot);

/* IS equation */
yis = gap[5:nt+4];
xis = gap[4:nt+3]~gap[3:nt+2];
//******************************************
//Line below fails
bis = invpd(xis'xis)*xis'yis;
ris = yis-xis*bis;
sis = sqrt(ris'ris/(nt-cols(xis)));

/* Phillips equation */
yph = dat[53:nt+52,3];
xph = dat[52:nt+51,3]~(dat[51:nt+50,3]+dat[50:nt+49,3]+dat[49:nt+48,3])/3;
xph = xph~(dat[48:nt+47,3]+dat[47:nt+46,3]+dat[46:nt+45,3]+dat[45:nt+44,3])/4;
xph = xph~gap[4:nt+3]~dat[52:nt+51,5]~dat[53:nt+52,6];
//******************************************
//Line below fails
bph = invpd(xph'xph)*xph'yph;
rph = yph-xph*bph;
sph = sqrt(rph'rph/(nt-cols(xph)));

/* Transition equation std devs */
s3 = 0.5;
d = 0.85;

/* Constructing data matrices and vector of initial values */
y = 100*dat[53:nt+52,1]~yph;
xr = 100*(dat[52:nt+51,1]~dat[51:nt+50,1])~xph[.,1:3]~xph[.,5:6];

startv = bis|bph[1:2]|bph[4:6]|d|sis|sph|s3;

output on;
"Starting values";
startv';
"";
output off;

err = reshape(mv,nt,2);
lf = reshape(mv,nt,1);
{val,f,g,retcode} = optmum(&li,startv);

/* res stores smoothed state, ref stores filtered state */

res = a2[2:nt+1,1];
ref = a1[2:nt+1,1];

/* Initial smoothed state and its covariance matrix are stored for
generating random draws during simulations */
stin = a2[2,.];
pp1 = p2s[1:nsv,.];
{tx,ty} = eigrs2(pp1);
dg = diagrv(eye(rows(tx)),tx);
hh2 = ty*sqrt(dg);

/* Computing gradients */
llf = lf;
dval = maxc(10^(-6)*abs(val')|ones(1,rows(val))*10^(-6));
bval = reshape(val,rows(val),rows(val))';
bval = diagrv(bval,val+dval);
i = 1;
do while i <= rows(val);
    call li(bval[.,i]);
    llf = llf~lf;
    i = i+1;
endo;
llf = (llf[.,2:rows(val)+1]-llf[.,1])./dval';
info = invpd(llf'llf);
bse = sqrt(diag(info));

output on;
"Likelihood value";
-f;
"";
"MLE Parameters of Model, SE, t Statistics";
val~bse~(abs(val)./bse);
"";
"Sum of coeffs on gap in IS equation";
sumc(val[1:2]);
"";

"Box-Pierce Q Statistics, L = 1,...,16, and 5% critical values";
bpq = zeros(16,2);
i = 1;
do while i <= 16;
    bpq[i,1] = ((err[1+i:nt,1]'err[1:nt-i,1])/(err[.,1]'err[.,1]))^2;
    bpq[i,2] = ((err[1+i:nt,2]'err[1:nt-i,2])/(err[.,2]'err[.,2]))^2;
    i = i+1;
endo;

i = 2;
do while i <= 16;
    bpq[i,.] = bpq[i,.]+bpq[i-1,.];
    i = i+1;
endo;
cv = {3.84,5.99,7.82,9.49,11.07,12.59,14.07,15.51,16.92,18.31,
    19.68,21.03,22.36,23.69,25,26.3};
nt*bpq~cv;
"";

/* Computing error bands for state vector using Monte Carlo */

indx = 1; /* Switches computation of initial state from GLS to draw */
cum1 = zeros(nt,1);
cum2 = zeros(nt,1);
{tx,ty} = eigrs2(info);
dg = diagrv(eye(rows(tx)),tx);
hh = ty*sqrt(dg);
i = 1;
do while i <= niter;
    theta = hh*rndns(rows(val),1,seed1)+val;
    call li(theta);
    cum1 = cum1+(a2[2:nt+1,1]-res[.,1]).*(a2[2:nt+1,1]-res[.,1]);
    j = 1;
    do while j <= nst-1;
        cum2[j] = cum2[j]+p2s[j*nsv+1,1];
        j = j+1;
    endo;
    cum2[nst:nt] = cum2[nst:nt]+ones(nt-nst+1,1)*p1s[(nst-1)*nsv+1,1];
    i = i+1;
endo;
cum1 = cum1/niter;
cum2 = cum2/niter;
bnd2 = sqrt(cum1+cum2);

"Mean SE";
meanc(bnd2);
(100*dat[53:nt+52,1]-res[.,1])~bnd2;
res/100;

end;
/* ----- Define the log likelihood function for each observation ------*/
proc li(inp);
    local p1,p2,i,f,fi,k,ldf,vv,j,flag1,c,x,om,yy,tmp;
    
    /* Insert parameters into system matrices */
    
    a1 = zeros(nt+1,nsv);
    a2 = zeros(nt+1,nsv);
    p1s = zeros(nst*nsv,nsv);
    p2s = zeros(nst*nsv,nsv);
    b = zeros(2,cols(xr));
    b[1,1:2] = inp[1:2]';
    b[2,1] = inp[5];
    b[2,3:4] = inp[3:4]';
    b[2,5] = 1-sumc(inp[3:4]);
    b[2,6:7] = inp[6:7]';
    z[1,1] = 1;
    z[1,2:3] = -inp[1:2]';
    z[2,2] = -inp[5];
    c = inp[8]|zeros(nsv-1,1);
    h[1,1] = inp[9]^2;
    h[2,2] = inp[10]^2;
    q[1,1] = inp[11]^2;
    
    /* Starting values for a(0|0), P(0|0) */
    
    if indx eq 1;
        p1 = pp1;
        a1[1,.] = (hh2*rndns(nsv,1,seed1)+stin')';
        goto flag1;
    endif;
    
    x = z|z*t|z*t*t|z*t*t*t;
    om = zeros(8,8);
    
    /* First initialize lower triangular off-diagonal elements */
    om[5:6,3:4] = z*t*q*z';
    om[7:8,3:4] = z*t*t*q*z';
    om[7:8,5:6] = z*(t*t*q*t'+t*q)*z';
    /* Initialize upper triangular off-diagonal elements by adding transpose */
    om = om+om';
    /* Initialize diagonal elements */
    om[1:2,1:2] = h;
    om[3:4,3:4] = z*q*z'+h;
    om[5:6,5:6] = z*(t*q*t'+q)*z'+h;
    om[7:8,7:8] = z*(t*t*q*t'*t'+t*q*t'+q)*z'+h;
    
    if det(om) le 10^(-6);
        "om" det(om);
        a1[1,.] = 100*gpot[5:3]';
        p1 = 2*eye(nsv);
        goto flag1;
    endif;
    om = invpd(om);
    if det(x'om*x) le 10^(-6);
        "x'om*x" det(x'om*x);
        a1[1,.] = 100*gpot[5:3]';
        p1 = 2*eye(nsv);
        goto flag1;
    endif;
    p1 = invpd(x'om*x);
    yy = y[1,.]'|y[2,.]'|y[3,.]'|y[4,.]';
    tmp = b*xr[1,.]'|(b*xr[2,.]'+z*c)|(b*xr[3,.]'+z*c+z*t*c);
    tmp = tmp|(b*xr[4,.]'+z*(eye(nsv)+t+t*t)*c);
    a1[1,.] = (p1*x'om*(yy-tmp))';
    tmp = yy-tmp-x*a1[1,.]';
    p1 = p1*(tmp'tmp)/3;
    
    flag1:
        
        lf = zeros(nt,1);
    
    /* Starting the Kalman filter:
    a1 stores a(t|t), t = 0,...,nt, a2 stores a(t|t-1), t = 1,...,nt
    p1s stores P(t|t), p2s stores P(t|t-1), t = 1,...,nst */
    
    i = 1;
    do while i <= nst;
        a2[i,.] = a1[i,.]*t'+c';
        err[i,.] = y[i,.]-a2[i,.]*z'-xr[i,.]*b';
        p2 = t*p1*t'+q;
        p2s[(i-1)*nsv+1:i*nsv,.] = p2;
        f = z*p2*z'+h;
        fi = inv(f);
        k = p2*z'fi;
        a1[i+1,.] = a2[i,.]+err[i,.]*k';
        p1 = (eye(nsv)-k*z)*p2;
        p1s[(i-1)*nsv+1:i*nsv,.] = p1;
        lf[i,1] = -0.5*(cols(y)*ln(2*pi)+ln(det(f))+err[i,.]*fi*err[i,.]');
        err[i,.] = err[i,.]./sqrt(diag(f))'; /* end filter */
        i = i+1;
    endo;
    
    ldf = ln(det(f));
    
    /* Begin steady state kalman filter */
    i = nst+1;
    do while i <= nt;
        a2[i,.] = a1[i,.]*t'+c';
        err[i,.] = y[i,.]-a2[i,.]*z'-xr[i,.]*b';
        a1[i+1,.] = a2[i,.]+err[i,.]*k';
        lf[i,1] = -0.5*(cols(y)*ln(2*pi)+ln(det(f))+err[i,.]*fi*err[i,.]');
        err[i,.] = err[i,.]./sqrt(diag(f))'; /* end filter */
        i = i+1;
    endo;
    
    /* Smoothing
    In a2, a(t|t-1) is overwritten by a(t-1|T)
    In p2s, P(t|t-1) is overwritten by P(t-1|T) */
    
    /* Recursively with values from steady state filter for t = nt,...,nst */
    
    j = p1s[(nst-2)*nsv+1:(nst-1)*nsv,.]*t'inv(p2s[(nst-1)*nsv+1:nst*nsv,.]);
    a2[nt+1,.] = a1[nt+1,.];
    
    i = 1;
    do while i <= nt+1-nst;
        a2[nt+1-i,.] = (a1[nt+1-i,.]'+j*(a2[nt+2-i,.]'-a2[nt+1-i,.]'))';
        i = i+1;
    endo;
    
    /* Recursively with values from startup period for t = nst-1,...,1 */
    
    p2s[(nst-1)*nsv+1:nst*nsv,.] = p1s[(nst-2)*nsv+1:(nst-1)*nsv,.]
        +j*(p1s[(nst-1)*nsv+1:nst*nsv,.]-p2s[(nst-1)*nsv+1:nst*nsv,.])*j';
    i = 1;
    do while i <= nst-2;
        j = p1s[(nst-2-i)*nsv+1:(nst-1-i)*nsv,.]
            *t'inv(p2s[(nst-1-i)*nsv+1:(nst-i)*nsv,.]);
        a2[nst-i,.] = (a1[nst-i,.]'+j*(a2[nst+1-i,.]'-a2[nst-i,.]'))';
        p2s[(nst-1-i)*nsv+1:(nst-i)*nsv,.] = p1s[(nst-2-i)*nsv+1:(nst-1-i)*nsv,.]
            +j*(p2s[(nst-i)*nsv+1:(nst+1-i)*nsv,.]
            -p2s[(nst-1-i)*nsv+1:(nst-i)*nsv,.])*j';
        i = i+1;
    endo;
    
    vv= sumc(lf);
    retp(-vv);
    
endp;

it's not working in the lines that are marked as failing. Basically i don't understand why this matrix is entirely zero

thank again



0



What matrix is entirely zero? Do you mean xph and xis, or the matrices made from xph'xph, xis'xis, or another one? Is the data set you are using an example dataset that came with the code, or is it your data?

aptech

1,773


0



I mean in the IS equation, xis and yis, when i print i just see 2 columns of zero

Normally it's not suppose to do

i use data coming from a excel sheet

thanks so much for taking time to answer me



0



7,34 4,48 4,44
7,35 4,48 4,23
7,36 4,49 5,90
7,36 4,48 -1,40
7,35 4,46 -2,95 12,97
7,34 4,44 -2,49 6,33
7,35 4,43 -2,25 4,17
7,34 4,42 -0,05 2,07
7,38 4,43 -0,65 4,10 1,53
7,41 4,46 2,12 4,06 1,53
7,45 4,49 8,20 2,02 1,65
7,47 4,50 6,76 4,00 1,79
7,48 4,52 12,58 3,96 1,79
7,50 4,52 2,92 5,87 1,79
7,52 4,51 0,47 0,00 1,79
7,52 4,51 5,17 13,37 1,79
7,53 4,52 1,57 30,71 1,79
7,53 4,52 0,13 25,27 1,79
7,54 4,52 2,81 -1,64 1,79
7,57 4,55 0,81 -1,64 1,79
7,59 4,56 1,47 4,91 2,01
7,60 4,56 0,62 3,24 2,05
7,59 4,55 2,22 3,21 2,05
7,57 4,53 1,80 6,35 2,05
7,57 4,52 2,09 1,57 1,89
7,57 4,51 -0,34 1,57 1,58
7,58 4,51 -1,22 7,74 1,53
7,60 4,52 -0,37 6,08 1,53
7,63 4,54 1,28 5,99 1,53
7,65 4,55 0,39 4,44 1,75
7,66 4,56 1,52 5,84 2,01
7,66 4,57 1,15 5,76 2,43
7,66 4,58 1,63 4,26 2,57
7,67 4,58 2,66 5,61 2,79
7,67 4,57 3,87 2,78 4,88 2,93
7,68 4,58 2,34 6,86 -1,00 3,09
7,69 4,58 3,60 -41,56 4,88 3,09
7,69 4,58 2,58 -4,95 0,82 3,09
7,70 4,57 3,14 -5,39 -1,99 3,31
7,69 4,55 2,05 -1,96 -5,13 3,34
7,66 4,53 4,99 0,31 -8,58 2,75
7,66 4,51 0,94 -8,09 -3,84 1,89
7,69 4,53 0,73 -2,29 -2,79 1,84
7,71 4,54 0,51 -12,47 -1,37 2,36
7,73 4,56 2,60 -6,36 7,46 2,72
7,75 4,58 1,93 -20,42 3,13 3,28
7,75 4,58 2,58 -12,05 1,55 3,73
7,76 4,58 2,38 -3,63 3,34 4,14
7,78 4,58 1,01 1,89 8,68 -1,95 4,14
7,77 4,58 1,52 2,10 -0,09 -0,47 4,02
7,78 4,58 1,60 2,34 3,37 1,63 3,33
7,76 4,57 1,54 2,15 10,32 -1,41 3,09
7,77 4,56 0,69 1,69 -4,09 -0,20 3,09
7,79 4,56 1,25 1,59 -4,29 -0,23 3,09
7,80 4,56 1,64 1,63 8,85 -0,84 3,09
7,82 4,58 0,68 1,51 -0,14 0,91 3,09
7,84 4,58 1,40 1,56 -8,20 -4,48 3,09
7,85 4,59 1,46 1,50 -4,66 0,78 3,09
7,86 4,59 1,22 1,50 -7,16 -1,53 3,09
7,86 4,58 0,59 1,35 -11,18 2,89 3,09
7,88 4,59 1,16 1,41 13,65 3,09 3,09
7,89 4,60 1,33 1,47 -1,59 1,74 3,09
7,91 4,60 1,51 1,54 10,07 1,87 3,52
7,92 4,61 1,75 1,62 2,19 2,27 3,61
7,94 4,61 1,57 1,59 -5,32 4,37 3,61
7,95 4,62 0,95 1,43 -0,32 2,16 3,61
7,96 4,62 1,14 1,46 -5,85 -0,29 3,61
7,97 4,63 1,13 1,49 2,01 1,69 3,83
7,99 4,65 1,60 1,65 -1,88 2,92 4,11
8,00 4,66 1,26 1,62 4,18 -1,48 4,22
8,02 4,66 1,20 1,58 5,22 2,87 4,22
8,05 4,67 1,12 1,54 -8,48 4,85 4,32
8,07 4,68 1,96 1,73 -3,52 2,27 4,73
8,08 4,69 3,09 2,06 1,56 4,23 5,11
8,08 4,70 3,21 2,21 5,63 -1,70 5,64
8,09 4,70 3,33 2,29 -9,64 3,31 5,80
8,10 4,69 1,71 1,94 0,44 2,09 5,01
8,10 4,69 2,51 1,97 1,65 -3,60 4,13
8,11 4,69 3,54 2,14 12,26 -1,96 4,03
8,11 4,70 3,93 2,39 -7,36 1,71 4,32
8,13 4,70 4,63 2,62 -7,17 4,42 4,97
8,15 4,71 4,37 2,85 10,40 2,67 6,25
8,16 4,72 4,16 3,28 4,73 -0,04 6,21
8,16 4,73 4,58 3,78 -17,41 2,85 6,18
8,18 4,73 4,31 4,42 6,72 2,62 6,88
8,18 4,74 4,75 4,82 -0,69 1,86 8,81
8,19 4,75 4,56 4,73 0,13 1,97 9,53
8,18 4,74 4,49 4,84 -4,66 15,40 9,49
8,18 4,74 4,17 4,57 0,50 3,96 9,07
8,18 4,73 4,12 4,40 7,28 4,52 8,32
8,19 4,72 4,44 4,52 9,80 12,68 7,04
8,18 4,71 5,83 5,41 6,98 4,61 5,81
8,21 4,72 4,89 5,07 9,74 6,69 3,99
8,21 4,72 4,59 5,40 9,34 -1,97 4,74
8,22 4,72 3,73 4,50 17,90 4,68 5,70
8,22 4,73 2,26 3,70 1,42 4,50 4,93
8,24 4,74 4,00 4,14 -9,75 10,62 3,66
8,26 4,75 2,75 2,72 17,47 11,84 4,46
8,27 4,76 2,90 3,33 -4,20 8,28 4,92
8,29 4,77 2,44 2,71 11,95 8,20 5,35
8,32 4,78 2,77 2,92 13,57 12,76 6,85
8,33 4,79 5,14 4,06 27,88 33,15 8,25
8,32 4,80 4,83 4,24 42,56 15,37 11,30
8,33 4,81 4,65 4,54 110,95 20,73 10,67
8,32 4,80 6,53 5,33 299,16 15,76 9,93
8,33 4,80 9,44 7,58 96,31 35,60 12,08
8,32 4,80 10,82 9,70 1,74 30,45 13,05
8,31 4,78 9,35 9,19 -7,82 20,02 9,94
8,30 4,75 7,48 7,61 12,85 10,04 6,60
8,31 4,74 5,95 6,24 -3,68 0,91 5,65
8,32 4,75 5,77 5,84 -8,36 -15,28 6,44
8,34 4,77 6,11 5,67 9,96 -4,84 5,64
8,36 4,78 5,74 5,27 15,14 4,30 5,02
8,37 4,78 4,79 4,69 3,88 9,12 5,41
8,37 4,78 6,50 6,11 1,49 8,80 5,50
8,38 4,79 6,69 5,90 8,61 2,44 5,06
8,39 4,80 6,37 5,70 15,86 14,81 4,84
8,41 4,82 6,17 5,67 7,81 13,74 5,37
8,43 4,83 6,70 6,07 -1,26 7,01 6,07
8,43 4,84 5,86 5,43 1,77 3,52 6,83
8,43 4,85 6,45 5,98 -1,21 11,00 7,09
8,47 4,88 7,06 6,37 -2,08 13,46 7,66
8,48 4,88 6,78 6,06 -0,46 6,98 8,55
8,49 4,89 6,76 6,12 1,86 8,53 10,20
8,49 4,90 6,11 5,71 19,72 16,25 10,75
8,50 4,91 6,96 6,42 62,61 8,15 10,87
8,50 4,91 7,03 6,42 100,18 4,52 11,73
8,51 4,92 8,52 7,46 47,71 19,72 14,76
8,51 4,92 10,13 8,44 68,39 18,98 16,50
8,49 4,90 9,25 7,63 35,66 7,06 13,70
8,49 4,89 8,78 7,57 8,05 12,99 10,47
8,50 4,91 8,55 7,60 12,13 6,08 17,43
8,52 4,91 8,12 7,30 29,10 3,14 18,31
8,52 4,91 7,61 7,02 12,78 -1,00 19,76
8,53 4,91 8,20 7,61 -27,40 -6,20 19,52
8,52 4,91 7,59 7,04 -10,17 4,92 14,77
8,50 4,89 5,79 5,77 -4,78 0,38 15,49
8,50 4,89 5,64 6,07 -18,65 -2,85 15,85
8,50 4,88 6,17 6,61 9,15 -7,62 11,81
8,50 4,87 5,47 6,14 -4,28 -2,38 9,87
8,51 4,88 5,12 6,14 -44,71 1,29 9,17
8,54 4,89 4,34 5,84 1,84 0,91 9,33
8,55 4,91 4,77 6,36 10,16 -0,70 10,07
8,57 4,93 4,11 6,07 -5,83 -1,59 10,03
8,59 4,95 3,52 5,76 -0,11 2,36 10,32
8,61 4,96 4,15 6,32 4,34 4,60 11,29
8,62 4,96 3,55 5,12 -7,53 -3,90 12,24
8,63 4,97 3,35 4,56 -3,79 -2,22 9,85
8,64 4,98 4,61 5,38 -13,23 -8,27 8,97
8,64 4,98 4,05 4,33 3,93 1,27 8,36
8,66 4,99 3,60 4,10 -19,06 1,96 8,34
8,67 4,99 4,13 4,56 7,29 9,81 8,56
8,68 4,99 3,43 3,83 -78,30 11,96 8,26
8,68 4,99 3,35 3,67 -196,26 5,55 7,27
8,69 4,99 3,74 3,94 -57,27 8,88 6,50
8,69 5,00 3,91 4,03 42,86 2,46 6,56
8,70 5,01 4,37 4,42 83,47 8,24 6,51
8,71 5,02 4,34 4,40 40,58 9,71 6,98
8,72 5,03 3,63 3,81 15,35 3,30 7,18
8,74 5,04 4,73 4,76 -16,79 10,55 7,27
8,74 5,04 3,12 3,38 -53,48 10,30 6,99
8,76 5,05 5,05 4,97 -1,23 9,58 7,52
8,76 5,06 4,41 4,50 -26,19 -2,01 8,43
8,77 5,07 4,34 4,37 -38,43 8,99 8,97
8,79 5,08 4,26 4,33 72,22 3,56 10,05
8,79 5,08 3,50 3,76 67,60 -0,79 10,36
8,80 5,08 2,99 3,23 -35,71 -3,97 9,65
8,80 5,08 4,46 4,22 21,03 1,54 9,13
8,81 5,09 3,97 4,08 38,83 3,71 8,72
8,81 5,09 5,24 4,75 -81,18 0,82 8,72
8,81 5,08 4,42 4,41 89,71 2,54 8,62
8,80 5,08 3,98 4,12 148,17 6,21 8,17
8,80 5,06 4,41 4,14 -142,42 4,41 6,74
8,81 5,06 3,51 3,94 -61,69 -2,94 6,12
8,81 5,06 3,59 3,86 -11,74 -2,93 5,89
8,81 5,06 3,89 3,79 28,54 3,76 5,00
8,82 5,05 4,48 3,98 -66,80 4,29 4,16
8,83 5,06 3,08 3,88 52,02 -1,54 3,90
8,84 5,06 2,07 3,67 25,69 4,37 3,36
8,85 5,06 3,31 3,51 -13,62 1,70 3,13
8,85 5,07 2,56 3,50 -34,54 -3,39 3,13
8,86 5,08 2,85 3,64 15,21 2,98 3,09
8,86 5,09 1,77 3,38 -45,91 0,95 3,15
8,88 5,10 2,31 3,14 -30,80 2,60 3,08
8,89 5,10 1,46 2,52 -42,39 0,99 3,31
8,90 5,12 2,60 2,41 59,06 2,72 4,08
8,91 5,12 3,06 2,58 36,40 5,11 4,65
8,92 5,13 1,85 2,52 -23,26 5,61 5,38
8,92 5,14 2,72 2,63 21,51 3,38 6,06
8,92 5,14 2,36 2,57 36,54 5,75 6,29
8,93 5,15 2,08 2,50 -38,78 2,31 6,05
8,94 5,15 1,84 2,21 1,76 -0,76 5,97
8,95 5,15 1,80 2,01 34,87 -0,95 5,59
8,96 5,16 1,70 1,85 42,84 -1,03 5,46
8,97 5,16 1,56 1,69 1,21 -1,43 5,53
8,98 5,17 2,21 1,83 52,46 0,42 5,50
8,99 5,18 2,31 2,05 -17,60 -0,40 5,50
9,00 5,19 2,26 2,24 -67,72 -2,32 5,76
9,01 5,19 1,05 1,83 -8,27 0,05 5,77
9,02 5,20 1,24 1,48 3,06 -0,62 5,74
9,04 5,20 1,59 1,33 -98,10 -3,17 5,76
9,04 5,21 1,65 1,46 -41,49 -1,93 5,73
9,05 5,21 1,57 1,54 -31,13 -3,44 5,77
9,07 5,22 1,45 1,51 -5,73 0,33 5,05
9,07 5,23 1,31 1,43 -37,59 -0,24 4,91
9,08 5,23 1,43 1,40 139,85 -0,80 4,93
9,09 5,24 1,44 1,39 94,21 1,12 5,30
9,11 5,24 1,70 1,50 67,98 1,40 5,53
9,12 5,25 2,21 1,76 66,60 1,41 5,93
9,13 5,25 1,80 1,83 1,57 1,97 6,57
9,13 5,24 1,26 1,61 35,04 1,68 6,83
9,13 5,24 1,83 1,63 4,08 1,34 6,78
9,13 5,24 2,80 1,93 -55,29 2,53 5,84
9,13 5,24 1,17 1,83 -15,17 -5,07 4,48
9,13 5,23 0,75 1,66 -11,80 -5,84 3,61
9,13 5,22 2,71 1,69 -98,15 -3,33 2,19
9,14 5,21 1,42 1,62 -0,30 -2,22 1,77
9,15 5,21 1,64 1,94 107,21 2,03 1,79

where there is a blank space it's because there are missing values



0



I know it is not the problem, but you don't want to invert a matrix because it's numerically not a good idea. I recommend the following. Instead of inv(X) or invpd(X), you should write eye(n)/X. This avoids the numerical problems of inverting a matrix.

Your Answer

8 Answers

0

The error "matrix not positive definite" happens when you are trying to invert a matrix using the function, invpd. The invpd function requires that the input matrix is positive definite. Most of the time it is used to invert a moment matrix (X'X) which should be positive definite unless there is some linear dependence in the variables.

When you say your matrix is full of zeros, do you mean that it is entirely zeros? Or that it just has quite a few of them? You might be having a problem loading your data correctly. Can you post a link to the code so we can offer more help?

0

Thank you for answering me.

I mean when i use the function "print" to see my matrix. I see that it's entirely zeros

0

If your matrix is entirely zeros, then it is certainly singular. Does the program simulate data, or is this data that you loaded from a file?

0

thank you again

well,

here is my code

/* ----------------------------------------------------------------------
rstar_s1.g: First-stage estimation of the model without hours in
Laubach-Williams, FEDS 2001-56. Last modified 09/03/02.
---------------------------------------------------------------------- */

library optmum;
optset;
output file = /mq/home/m1hxl00/work/nri/nrv2/n2v1.out reset;
format /rd 8,4;

load dat[218,7] = /mq/home/m1hxl00/work/nri/nrv2/nr2_0902.dat;
dat[.,5] = dat[.,5]-dat[.,3]; /* Relative oil price inflation */
dat[.,6] = dat[.,6]-dat[.,3]; /* Relative import price inflation */
dat[.,7] = dat[.,7]-dat[.,4]; /* Ex ante real rate */
mv = miss(0,0);

nt = 166; /* Sample 61:1 - 02:2 */
nar = 7; /* Number of regressors */
nsv = 3; /* Number of state variables */
nst = nt; /* Startup periods for filter */
niter = 1000; /* Number of draws for generating error bands */
seed1 = 40;
indx = 0; /* Index for initialisation of P(0|0) during MC simulation */

/* Setting up system matrices:
a1 filtered state a(t|t)
a2 smoothed state a(t|T)
p1s covariance matrix of filtered state
p2s covariance matrix of smoothed state
b coefficients on explanatory variables in measurement equation
xr regressor matrix in measurement equation
z coefficients on state vector in measurement equation
h covariance matrix of measurement equation error
t transition matrix in transition equation
q covariance matrix of transition equation error */

a1 = zeros(nt+1,nsv);
a2 = zeros(nt+1,nsv);
p1s = zeros(nst*nsv,nsv);
p2s = zeros(nst*nsv,nsv);
b = zeros(2,nar);
z = zeros(2,nsv);
h = zeros(2,2);
t = zeros(nsv,nsv);
t[1:2,1] = ones(2,1);
t[3,2] = 1;
q = zeros(nsv,nsv);

/* Computing starting values for parameters */

/* Potential XBO proxied by segmented trend 60:1 to 00:4 */
xr = ones(nt+4,1)~seqa(1,1,nt+4);
xr = xr~(zeros(56,1)|seqa(1,1,nt-52))~(zeros(142,1)|seqa(1,1,nt-138));
xi = invpd(xr'xr);
bpot = xi*xr'dat[49:nt+52,1];
gpot = xr*bpot;
gap = 100*(dat[49:nt+52,1]-xr*bpot);

/* IS equation */
yis = gap[5:nt+4];
xis = gap[4:nt+3]~gap[3:nt+2];
//******************************************
//Line below fails
bis = invpd(xis'xis)*xis'yis;
ris = yis-xis*bis;
sis = sqrt(ris'ris/(nt-cols(xis)));

/* Phillips equation */
yph = dat[53:nt+52,3];
xph = dat[52:nt+51,3]~(dat[51:nt+50,3]+dat[50:nt+49,3]+dat[49:nt+48,3])/3;
xph = xph~(dat[48:nt+47,3]+dat[47:nt+46,3]+dat[46:nt+45,3]+dat[45:nt+44,3])/4;
xph = xph~gap[4:nt+3]~dat[52:nt+51,5]~dat[53:nt+52,6];
//******************************************
//Line below fails
bph = invpd(xph'xph)*xph'yph;
rph = yph-xph*bph;
sph = sqrt(rph'rph/(nt-cols(xph)));

/* Transition equation std devs */
s3 = 0.5;
d = 0.85;

/* Constructing data matrices and vector of initial values */
y = 100*dat[53:nt+52,1]~yph;
xr = 100*(dat[52:nt+51,1]~dat[51:nt+50,1])~xph[.,1:3]~xph[.,5:6];

startv = bis|bph[1:2]|bph[4:6]|d|sis|sph|s3;

output on;
"Starting values";
startv';
"";
output off;

err = reshape(mv,nt,2);
lf = reshape(mv,nt,1);
{val,f,g,retcode} = optmum(&li,startv);

/* res stores smoothed state, ref stores filtered state */

res = a2[2:nt+1,1];
ref = a1[2:nt+1,1];

/* Initial smoothed state and its covariance matrix are stored for
generating random draws during simulations */
stin = a2[2,.];
pp1 = p2s[1:nsv,.];
{tx,ty} = eigrs2(pp1);
dg = diagrv(eye(rows(tx)),tx);
hh2 = ty*sqrt(dg);

/* Computing gradients */
llf = lf;
dval = maxc(10^(-6)*abs(val')|ones(1,rows(val))*10^(-6));
bval = reshape(val,rows(val),rows(val))';
bval = diagrv(bval,val+dval);
i = 1;
do while i <= rows(val);
    call li(bval[.,i]);
    llf = llf~lf;
    i = i+1;
endo;
llf = (llf[.,2:rows(val)+1]-llf[.,1])./dval';
info = invpd(llf'llf);
bse = sqrt(diag(info));

output on;
"Likelihood value";
-f;
"";
"MLE Parameters of Model, SE, t Statistics";
val~bse~(abs(val)./bse);
"";
"Sum of coeffs on gap in IS equation";
sumc(val[1:2]);
"";

"Box-Pierce Q Statistics, L = 1,...,16, and 5% critical values";
bpq = zeros(16,2);
i = 1;
do while i <= 16;
    bpq[i,1] = ((err[1+i:nt,1]'err[1:nt-i,1])/(err[.,1]'err[.,1]))^2;
    bpq[i,2] = ((err[1+i:nt,2]'err[1:nt-i,2])/(err[.,2]'err[.,2]))^2;
    i = i+1;
endo;

i = 2;
do while i <= 16;
    bpq[i,.] = bpq[i,.]+bpq[i-1,.];
    i = i+1;
endo;
cv = {3.84,5.99,7.82,9.49,11.07,12.59,14.07,15.51,16.92,18.31,
    19.68,21.03,22.36,23.69,25,26.3};
nt*bpq~cv;
"";

/* Computing error bands for state vector using Monte Carlo */

indx = 1; /* Switches computation of initial state from GLS to draw */
cum1 = zeros(nt,1);
cum2 = zeros(nt,1);
{tx,ty} = eigrs2(info);
dg = diagrv(eye(rows(tx)),tx);
hh = ty*sqrt(dg);
i = 1;
do while i <= niter;
    theta = hh*rndns(rows(val),1,seed1)+val;
    call li(theta);
    cum1 = cum1+(a2[2:nt+1,1]-res[.,1]).*(a2[2:nt+1,1]-res[.,1]);
    j = 1;
    do while j <= nst-1;
        cum2[j] = cum2[j]+p2s[j*nsv+1,1];
        j = j+1;
    endo;
    cum2[nst:nt] = cum2[nst:nt]+ones(nt-nst+1,1)*p1s[(nst-1)*nsv+1,1];
    i = i+1;
endo;
cum1 = cum1/niter;
cum2 = cum2/niter;
bnd2 = sqrt(cum1+cum2);

"Mean SE";
meanc(bnd2);
(100*dat[53:nt+52,1]-res[.,1])~bnd2;
res/100;

end;
/* ----- Define the log likelihood function for each observation ------*/
proc li(inp);
    local p1,p2,i,f,fi,k,ldf,vv,j,flag1,c,x,om,yy,tmp;
    
    /* Insert parameters into system matrices */
    
    a1 = zeros(nt+1,nsv);
    a2 = zeros(nt+1,nsv);
    p1s = zeros(nst*nsv,nsv);
    p2s = zeros(nst*nsv,nsv);
    b = zeros(2,cols(xr));
    b[1,1:2] = inp[1:2]';
    b[2,1] = inp[5];
    b[2,3:4] = inp[3:4]';
    b[2,5] = 1-sumc(inp[3:4]);
    b[2,6:7] = inp[6:7]';
    z[1,1] = 1;
    z[1,2:3] = -inp[1:2]';
    z[2,2] = -inp[5];
    c = inp[8]|zeros(nsv-1,1);
    h[1,1] = inp[9]^2;
    h[2,2] = inp[10]^2;
    q[1,1] = inp[11]^2;
    
    /* Starting values for a(0|0), P(0|0) */
    
    if indx eq 1;
        p1 = pp1;
        a1[1,.] = (hh2*rndns(nsv,1,seed1)+stin')';
        goto flag1;
    endif;
    
    x = z|z*t|z*t*t|z*t*t*t;
    om = zeros(8,8);
    
    /* First initialize lower triangular off-diagonal elements */
    om[5:6,3:4] = z*t*q*z';
    om[7:8,3:4] = z*t*t*q*z';
    om[7:8,5:6] = z*(t*t*q*t'+t*q)*z';
    /* Initialize upper triangular off-diagonal elements by adding transpose */
    om = om+om';
    /* Initialize diagonal elements */
    om[1:2,1:2] = h;
    om[3:4,3:4] = z*q*z'+h;
    om[5:6,5:6] = z*(t*q*t'+q)*z'+h;
    om[7:8,7:8] = z*(t*t*q*t'*t'+t*q*t'+q)*z'+h;
    
    if det(om) le 10^(-6);
        "om" det(om);
        a1[1,.] = 100*gpot[5:3]';
        p1 = 2*eye(nsv);
        goto flag1;
    endif;
    om = invpd(om);
    if det(x'om*x) le 10^(-6);
        "x'om*x" det(x'om*x);
        a1[1,.] = 100*gpot[5:3]';
        p1 = 2*eye(nsv);
        goto flag1;
    endif;
    p1 = invpd(x'om*x);
    yy = y[1,.]'|y[2,.]'|y[3,.]'|y[4,.]';
    tmp = b*xr[1,.]'|(b*xr[2,.]'+z*c)|(b*xr[3,.]'+z*c+z*t*c);
    tmp = tmp|(b*xr[4,.]'+z*(eye(nsv)+t+t*t)*c);
    a1[1,.] = (p1*x'om*(yy-tmp))';
    tmp = yy-tmp-x*a1[1,.]';
    p1 = p1*(tmp'tmp)/3;
    
    flag1:
        
        lf = zeros(nt,1);
    
    /* Starting the Kalman filter:
    a1 stores a(t|t), t = 0,...,nt, a2 stores a(t|t-1), t = 1,...,nt
    p1s stores P(t|t), p2s stores P(t|t-1), t = 1,...,nst */
    
    i = 1;
    do while i <= nst;
        a2[i,.] = a1[i,.]*t'+c';
        err[i,.] = y[i,.]-a2[i,.]*z'-xr[i,.]*b';
        p2 = t*p1*t'+q;
        p2s[(i-1)*nsv+1:i*nsv,.] = p2;
        f = z*p2*z'+h;
        fi = inv(f);
        k = p2*z'fi;
        a1[i+1,.] = a2[i,.]+err[i,.]*k';
        p1 = (eye(nsv)-k*z)*p2;
        p1s[(i-1)*nsv+1:i*nsv,.] = p1;
        lf[i,1] = -0.5*(cols(y)*ln(2*pi)+ln(det(f))+err[i,.]*fi*err[i,.]');
        err[i,.] = err[i,.]./sqrt(diag(f))'; /* end filter */
        i = i+1;
    endo;
    
    ldf = ln(det(f));
    
    /* Begin steady state kalman filter */
    i = nst+1;
    do while i <= nt;
        a2[i,.] = a1[i,.]*t'+c';
        err[i,.] = y[i,.]-a2[i,.]*z'-xr[i,.]*b';
        a1[i+1,.] = a2[i,.]+err[i,.]*k';
        lf[i,1] = -0.5*(cols(y)*ln(2*pi)+ln(det(f))+err[i,.]*fi*err[i,.]');
        err[i,.] = err[i,.]./sqrt(diag(f))'; /* end filter */
        i = i+1;
    endo;
    
    /* Smoothing
    In a2, a(t|t-1) is overwritten by a(t-1|T)
    In p2s, P(t|t-1) is overwritten by P(t-1|T) */
    
    /* Recursively with values from steady state filter for t = nt,...,nst */
    
    j = p1s[(nst-2)*nsv+1:(nst-1)*nsv,.]*t'inv(p2s[(nst-1)*nsv+1:nst*nsv,.]);
    a2[nt+1,.] = a1[nt+1,.];
    
    i = 1;
    do while i <= nt+1-nst;
        a2[nt+1-i,.] = (a1[nt+1-i,.]'+j*(a2[nt+2-i,.]'-a2[nt+1-i,.]'))';
        i = i+1;
    endo;
    
    /* Recursively with values from startup period for t = nst-1,...,1 */
    
    p2s[(nst-1)*nsv+1:nst*nsv,.] = p1s[(nst-2)*nsv+1:(nst-1)*nsv,.]
        +j*(p1s[(nst-1)*nsv+1:nst*nsv,.]-p2s[(nst-1)*nsv+1:nst*nsv,.])*j';
    i = 1;
    do while i <= nst-2;
        j = p1s[(nst-2-i)*nsv+1:(nst-1-i)*nsv,.]
            *t'inv(p2s[(nst-1-i)*nsv+1:(nst-i)*nsv,.]);
        a2[nst-i,.] = (a1[nst-i,.]'+j*(a2[nst+1-i,.]'-a2[nst-i,.]'))';
        p2s[(nst-1-i)*nsv+1:(nst-i)*nsv,.] = p1s[(nst-2-i)*nsv+1:(nst-1-i)*nsv,.]
            +j*(p2s[(nst-i)*nsv+1:(nst+1-i)*nsv,.]
            -p2s[(nst-1-i)*nsv+1:(nst-i)*nsv,.])*j';
        i = i+1;
    endo;
    
    vv= sumc(lf);
    retp(-vv);
    
endp;

it's not working in the lines that are marked as failing. Basically i don't understand why this matrix is entirely zero

thank again

0

What matrix is entirely zero? Do you mean xph and xis, or the matrices made from xph'xph, xis'xis, or another one? Is the data set you are using an example dataset that came with the code, or is it your data?

0

I mean in the IS equation, xis and yis, when i print i just see 2 columns of zero

Normally it's not suppose to do

i use data coming from a excel sheet

thanks so much for taking time to answer me

0

7,34 4,48 4,44
7,35 4,48 4,23
7,36 4,49 5,90
7,36 4,48 -1,40
7,35 4,46 -2,95 12,97
7,34 4,44 -2,49 6,33
7,35 4,43 -2,25 4,17
7,34 4,42 -0,05 2,07
7,38 4,43 -0,65 4,10 1,53
7,41 4,46 2,12 4,06 1,53
7,45 4,49 8,20 2,02 1,65
7,47 4,50 6,76 4,00 1,79
7,48 4,52 12,58 3,96 1,79
7,50 4,52 2,92 5,87 1,79
7,52 4,51 0,47 0,00 1,79
7,52 4,51 5,17 13,37 1,79
7,53 4,52 1,57 30,71 1,79
7,53 4,52 0,13 25,27 1,79
7,54 4,52 2,81 -1,64 1,79
7,57 4,55 0,81 -1,64 1,79
7,59 4,56 1,47 4,91 2,01
7,60 4,56 0,62 3,24 2,05
7,59 4,55 2,22 3,21 2,05
7,57 4,53 1,80 6,35 2,05
7,57 4,52 2,09 1,57 1,89
7,57 4,51 -0,34 1,57 1,58
7,58 4,51 -1,22 7,74 1,53
7,60 4,52 -0,37 6,08 1,53
7,63 4,54 1,28 5,99 1,53
7,65 4,55 0,39 4,44 1,75
7,66 4,56 1,52 5,84 2,01
7,66 4,57 1,15 5,76 2,43
7,66 4,58 1,63 4,26 2,57
7,67 4,58 2,66 5,61 2,79
7,67 4,57 3,87 2,78 4,88 2,93
7,68 4,58 2,34 6,86 -1,00 3,09
7,69 4,58 3,60 -41,56 4,88 3,09
7,69 4,58 2,58 -4,95 0,82 3,09
7,70 4,57 3,14 -5,39 -1,99 3,31
7,69 4,55 2,05 -1,96 -5,13 3,34
7,66 4,53 4,99 0,31 -8,58 2,75
7,66 4,51 0,94 -8,09 -3,84 1,89
7,69 4,53 0,73 -2,29 -2,79 1,84
7,71 4,54 0,51 -12,47 -1,37 2,36
7,73 4,56 2,60 -6,36 7,46 2,72
7,75 4,58 1,93 -20,42 3,13 3,28
7,75 4,58 2,58 -12,05 1,55 3,73
7,76 4,58 2,38 -3,63 3,34 4,14
7,78 4,58 1,01 1,89 8,68 -1,95 4,14
7,77 4,58 1,52 2,10 -0,09 -0,47 4,02
7,78 4,58 1,60 2,34 3,37 1,63 3,33
7,76 4,57 1,54 2,15 10,32 -1,41 3,09
7,77 4,56 0,69 1,69 -4,09 -0,20 3,09
7,79 4,56 1,25 1,59 -4,29 -0,23 3,09
7,80 4,56 1,64 1,63 8,85 -0,84 3,09
7,82 4,58 0,68 1,51 -0,14 0,91 3,09
7,84 4,58 1,40 1,56 -8,20 -4,48 3,09
7,85 4,59 1,46 1,50 -4,66 0,78 3,09
7,86 4,59 1,22 1,50 -7,16 -1,53 3,09
7,86 4,58 0,59 1,35 -11,18 2,89 3,09
7,88 4,59 1,16 1,41 13,65 3,09 3,09
7,89 4,60 1,33 1,47 -1,59 1,74 3,09
7,91 4,60 1,51 1,54 10,07 1,87 3,52
7,92 4,61 1,75 1,62 2,19 2,27 3,61
7,94 4,61 1,57 1,59 -5,32 4,37 3,61
7,95 4,62 0,95 1,43 -0,32 2,16 3,61
7,96 4,62 1,14 1,46 -5,85 -0,29 3,61
7,97 4,63 1,13 1,49 2,01 1,69 3,83
7,99 4,65 1,60 1,65 -1,88 2,92 4,11
8,00 4,66 1,26 1,62 4,18 -1,48 4,22
8,02 4,66 1,20 1,58 5,22 2,87 4,22
8,05 4,67 1,12 1,54 -8,48 4,85 4,32
8,07 4,68 1,96 1,73 -3,52 2,27 4,73
8,08 4,69 3,09 2,06 1,56 4,23 5,11
8,08 4,70 3,21 2,21 5,63 -1,70 5,64
8,09 4,70 3,33 2,29 -9,64 3,31 5,80
8,10 4,69 1,71 1,94 0,44 2,09 5,01
8,10 4,69 2,51 1,97 1,65 -3,60 4,13
8,11 4,69 3,54 2,14 12,26 -1,96 4,03
8,11 4,70 3,93 2,39 -7,36 1,71 4,32
8,13 4,70 4,63 2,62 -7,17 4,42 4,97
8,15 4,71 4,37 2,85 10,40 2,67 6,25
8,16 4,72 4,16 3,28 4,73 -0,04 6,21
8,16 4,73 4,58 3,78 -17,41 2,85 6,18
8,18 4,73 4,31 4,42 6,72 2,62 6,88
8,18 4,74 4,75 4,82 -0,69 1,86 8,81
8,19 4,75 4,56 4,73 0,13 1,97 9,53
8,18 4,74 4,49 4,84 -4,66 15,40 9,49
8,18 4,74 4,17 4,57 0,50 3,96 9,07
8,18 4,73 4,12 4,40 7,28 4,52 8,32
8,19 4,72 4,44 4,52 9,80 12,68 7,04
8,18 4,71 5,83 5,41 6,98 4,61 5,81
8,21 4,72 4,89 5,07 9,74 6,69 3,99
8,21 4,72 4,59 5,40 9,34 -1,97 4,74
8,22 4,72 3,73 4,50 17,90 4,68 5,70
8,22 4,73 2,26 3,70 1,42 4,50 4,93
8,24 4,74 4,00 4,14 -9,75 10,62 3,66
8,26 4,75 2,75 2,72 17,47 11,84 4,46
8,27 4,76 2,90 3,33 -4,20 8,28 4,92
8,29 4,77 2,44 2,71 11,95 8,20 5,35
8,32 4,78 2,77 2,92 13,57 12,76 6,85
8,33 4,79 5,14 4,06 27,88 33,15 8,25
8,32 4,80 4,83 4,24 42,56 15,37 11,30
8,33 4,81 4,65 4,54 110,95 20,73 10,67
8,32 4,80 6,53 5,33 299,16 15,76 9,93
8,33 4,80 9,44 7,58 96,31 35,60 12,08
8,32 4,80 10,82 9,70 1,74 30,45 13,05
8,31 4,78 9,35 9,19 -7,82 20,02 9,94
8,30 4,75 7,48 7,61 12,85 10,04 6,60
8,31 4,74 5,95 6,24 -3,68 0,91 5,65
8,32 4,75 5,77 5,84 -8,36 -15,28 6,44
8,34 4,77 6,11 5,67 9,96 -4,84 5,64
8,36 4,78 5,74 5,27 15,14 4,30 5,02
8,37 4,78 4,79 4,69 3,88 9,12 5,41
8,37 4,78 6,50 6,11 1,49 8,80 5,50
8,38 4,79 6,69 5,90 8,61 2,44 5,06
8,39 4,80 6,37 5,70 15,86 14,81 4,84
8,41 4,82 6,17 5,67 7,81 13,74 5,37
8,43 4,83 6,70 6,07 -1,26 7,01 6,07
8,43 4,84 5,86 5,43 1,77 3,52 6,83
8,43 4,85 6,45 5,98 -1,21 11,00 7,09
8,47 4,88 7,06 6,37 -2,08 13,46 7,66
8,48 4,88 6,78 6,06 -0,46 6,98 8,55
8,49 4,89 6,76 6,12 1,86 8,53 10,20
8,49 4,90 6,11 5,71 19,72 16,25 10,75
8,50 4,91 6,96 6,42 62,61 8,15 10,87
8,50 4,91 7,03 6,42 100,18 4,52 11,73
8,51 4,92 8,52 7,46 47,71 19,72 14,76
8,51 4,92 10,13 8,44 68,39 18,98 16,50
8,49 4,90 9,25 7,63 35,66 7,06 13,70
8,49 4,89 8,78 7,57 8,05 12,99 10,47
8,50 4,91 8,55 7,60 12,13 6,08 17,43
8,52 4,91 8,12 7,30 29,10 3,14 18,31
8,52 4,91 7,61 7,02 12,78 -1,00 19,76
8,53 4,91 8,20 7,61 -27,40 -6,20 19,52
8,52 4,91 7,59 7,04 -10,17 4,92 14,77
8,50 4,89 5,79 5,77 -4,78 0,38 15,49
8,50 4,89 5,64 6,07 -18,65 -2,85 15,85
8,50 4,88 6,17 6,61 9,15 -7,62 11,81
8,50 4,87 5,47 6,14 -4,28 -2,38 9,87
8,51 4,88 5,12 6,14 -44,71 1,29 9,17
8,54 4,89 4,34 5,84 1,84 0,91 9,33
8,55 4,91 4,77 6,36 10,16 -0,70 10,07
8,57 4,93 4,11 6,07 -5,83 -1,59 10,03
8,59 4,95 3,52 5,76 -0,11 2,36 10,32
8,61 4,96 4,15 6,32 4,34 4,60 11,29
8,62 4,96 3,55 5,12 -7,53 -3,90 12,24
8,63 4,97 3,35 4,56 -3,79 -2,22 9,85
8,64 4,98 4,61 5,38 -13,23 -8,27 8,97
8,64 4,98 4,05 4,33 3,93 1,27 8,36
8,66 4,99 3,60 4,10 -19,06 1,96 8,34
8,67 4,99 4,13 4,56 7,29 9,81 8,56
8,68 4,99 3,43 3,83 -78,30 11,96 8,26
8,68 4,99 3,35 3,67 -196,26 5,55 7,27
8,69 4,99 3,74 3,94 -57,27 8,88 6,50
8,69 5,00 3,91 4,03 42,86 2,46 6,56
8,70 5,01 4,37 4,42 83,47 8,24 6,51
8,71 5,02 4,34 4,40 40,58 9,71 6,98
8,72 5,03 3,63 3,81 15,35 3,30 7,18
8,74 5,04 4,73 4,76 -16,79 10,55 7,27
8,74 5,04 3,12 3,38 -53,48 10,30 6,99
8,76 5,05 5,05 4,97 -1,23 9,58 7,52
8,76 5,06 4,41 4,50 -26,19 -2,01 8,43
8,77 5,07 4,34 4,37 -38,43 8,99 8,97
8,79 5,08 4,26 4,33 72,22 3,56 10,05
8,79 5,08 3,50 3,76 67,60 -0,79 10,36
8,80 5,08 2,99 3,23 -35,71 -3,97 9,65
8,80 5,08 4,46 4,22 21,03 1,54 9,13
8,81 5,09 3,97 4,08 38,83 3,71 8,72
8,81 5,09 5,24 4,75 -81,18 0,82 8,72
8,81 5,08 4,42 4,41 89,71 2,54 8,62
8,80 5,08 3,98 4,12 148,17 6,21 8,17
8,80 5,06 4,41 4,14 -142,42 4,41 6,74
8,81 5,06 3,51 3,94 -61,69 -2,94 6,12
8,81 5,06 3,59 3,86 -11,74 -2,93 5,89
8,81 5,06 3,89 3,79 28,54 3,76 5,00
8,82 5,05 4,48 3,98 -66,80 4,29 4,16
8,83 5,06 3,08 3,88 52,02 -1,54 3,90
8,84 5,06 2,07 3,67 25,69 4,37 3,36
8,85 5,06 3,31 3,51 -13,62 1,70 3,13
8,85 5,07 2,56 3,50 -34,54 -3,39 3,13
8,86 5,08 2,85 3,64 15,21 2,98 3,09
8,86 5,09 1,77 3,38 -45,91 0,95 3,15
8,88 5,10 2,31 3,14 -30,80 2,60 3,08
8,89 5,10 1,46 2,52 -42,39 0,99 3,31
8,90 5,12 2,60 2,41 59,06 2,72 4,08
8,91 5,12 3,06 2,58 36,40 5,11 4,65
8,92 5,13 1,85 2,52 -23,26 5,61 5,38
8,92 5,14 2,72 2,63 21,51 3,38 6,06
8,92 5,14 2,36 2,57 36,54 5,75 6,29
8,93 5,15 2,08 2,50 -38,78 2,31 6,05
8,94 5,15 1,84 2,21 1,76 -0,76 5,97
8,95 5,15 1,80 2,01 34,87 -0,95 5,59
8,96 5,16 1,70 1,85 42,84 -1,03 5,46
8,97 5,16 1,56 1,69 1,21 -1,43 5,53
8,98 5,17 2,21 1,83 52,46 0,42 5,50
8,99 5,18 2,31 2,05 -17,60 -0,40 5,50
9,00 5,19 2,26 2,24 -67,72 -2,32 5,76
9,01 5,19 1,05 1,83 -8,27 0,05 5,77
9,02 5,20 1,24 1,48 3,06 -0,62 5,74
9,04 5,20 1,59 1,33 -98,10 -3,17 5,76
9,04 5,21 1,65 1,46 -41,49 -1,93 5,73
9,05 5,21 1,57 1,54 -31,13 -3,44 5,77
9,07 5,22 1,45 1,51 -5,73 0,33 5,05
9,07 5,23 1,31 1,43 -37,59 -0,24 4,91
9,08 5,23 1,43 1,40 139,85 -0,80 4,93
9,09 5,24 1,44 1,39 94,21 1,12 5,30
9,11 5,24 1,70 1,50 67,98 1,40 5,53
9,12 5,25 2,21 1,76 66,60 1,41 5,93
9,13 5,25 1,80 1,83 1,57 1,97 6,57
9,13 5,24 1,26 1,61 35,04 1,68 6,83
9,13 5,24 1,83 1,63 4,08 1,34 6,78
9,13 5,24 2,80 1,93 -55,29 2,53 5,84
9,13 5,24 1,17 1,83 -15,17 -5,07 4,48
9,13 5,23 0,75 1,66 -11,80 -5,84 3,61
9,13 5,22 2,71 1,69 -98,15 -3,33 2,19
9,14 5,21 1,42 1,62 -0,30 -2,22 1,77
9,15 5,21 1,64 1,94 107,21 2,03 1,79

where there is a blank space it's because there are missing values

0

I know it is not the problem, but you don't want to invert a matrix because it's numerically not a good idea. I recommend the following. Instead of inv(X) or invpd(X), you should write eye(n)/X. This avoids the numerical problems of inverting a matrix.


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.