Home > . > DiffuseLikelihoodH3corr.m

DiffuseLikelihoodH3corr

PURPOSE ^

stephane.adjemian@cepremap.cnrs.fr [12-13-2004]

SYNOPSIS ^

function LIK = DiffuseLikelihoodH3corr(T,R,Q,H,Pinf,Pstar,Y,trend,start)

DESCRIPTION ^

 stephane.adjemian@cepremap.cnrs.fr [12-13-2004]

 Same as DiffuseLikelihoodH3 but allows correlation between the measurement
 errors (this is not a problem with the multivariate approach).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function LIK = DiffuseLikelihoodH3corr(T,R,Q,H,Pinf,Pstar,Y,trend,start)
0002 % stephane.adjemian@cepremap.cnrs.fr [12-13-2004]
0003 %
0004 % Same as DiffuseLikelihoodH3 but allows correlation between the measurement
0005 % errors (this is not a problem with the multivariate approach).
0006 
0007 global bayestopt_ options_
0008   
0009 mf  = bayestopt_.mf;
0010 pp     = size(Y,1);
0011 mm     = size(T,1);
0012 rr       = size(Q,1);    
0013 smpl   = size(Y,2);
0014 T   = cat(1,cat(2,T,zeros(mm,pp)),zeros(pp,mm+pp));
0015 R   = cat(1,cat(2,R,zeros(mm,pp)),cat(2,zeros(pp,rr),eye(pp)));
0016 Q   = cat(1,cat(2,Q,zeros(rr,pp)),cat(2,zeros(pp,rr),H));
0017 if size(Pinf,1) % Otherwise Pinf = 0 (no unit root)
0018     Pinf   = cat(1,cat(2,Pinf,zeros(mm,pp)),zeros(pp,mm+pp));
0019 end
0020 Pstar  = cat(1,cat(2,Pstar,zeros(mm,pp)),cat(2,zeros(pp,mm),H));
0021 a      = zeros(mm+pp,1);
0022 QQ     = R*Q*transpose(R);
0023 t      = 0;
0024 lik    = zeros(smpl+1,1);
0025 lik(smpl+1) = smpl*pp*log(2*pi); %% the constant of minus two times the log-likelihood
0026 notsteady     = 1;
0027 crit          = options_.kalman_tol;
0028 newRank          = rank(Pinf,crit);
0029 
0030 while rank(Pinf,crit) & t < smpl %% Matrix Finf is assumed to be zero
0031     t = t+1;
0032     for i=1:pp
0033         v(i)     = Y(i,t)-a(mf(i))-a(mm+i)-trend(i,t);
0034         Fstar     = Pstar(mf(i),mf(i))+Pstar(mm+i,mm+i);
0035         Finf    = Pinf(mf(i),mf(i));
0036         Kstar     = Pstar(:,mf(i))+Pstar(:,mm+i);
0037         if Finf > crit
0038             Kinf    = Pinf(:,mf(i));
0039             a        = a + Kinf*v(i)/Finf;
0040             Pstar    = Pstar + Kinf*transpose(Kinf)*Fstar/(Finf*Finf) - ...
0041                         (Kstar*transpose(Kinf)+Kinf*transpose(Kstar))/Finf;
0042             Pinf    = Pinf - Kinf*transpose(Kinf)/Finf;
0043             lik(t)     = lik(t) + log(Finf);
0044         else %% Note that : (1) rank(Pinf)=0 implies that Finf = 0, (2) outside this loop (when for some i and t the condition
0045              %% rank(Pinf)=0 is satisfied we have P = Pstar and F = Fstar and (3) Finf = 0 does not imply that
0046              %% rank(Pinf)=0. [stphane,11-03-2004].
0047             if rank(Pinf) == 0
0048                 lik(t)    = lik(t) + log(Fstar) + v(i)*v(i)/Fstar;
0049             end
0050             a         = a + Kstar*v(i)/Fstar;
0051             Pstar    = Pstar - Kstar*transpose(Kstar)/Fstar;                    
0052         end
0053         oldRank = rank(Pinf,crit);
0054         a         = T*a;
0055         Pstar     = T*Pstar*transpose(T)+QQ;
0056         Pinf    = T*Pinf*transpose(T);
0057         newRank = rank(Pinf,crit);
0058         if oldRank ~= newRank
0059             disp('DiffuseLiklihoodH3 :: T does influence the rank of Pinf!')    
0060         end                 
0061     end
0062 end
0063 if t == smpl                                                           
0064   error(['There isn''t enough information to estimate the initial' ... 
0065      ' conditions of the nonstationary variables']);                   
0066 end                                                                    
0067 while notsteady & t < smpl
0068     t = t+1;
0069     for i=1:pp
0070         v(i) = Y(i,t) - a(mf(i)) - trend(i,t) -a(mm+i);
0071         Fi   = Pstar(mf(i),mf(i))+Pstar(mm+i,mm+i);
0072         if Fi > crit
0073             Ki        = Pstar(:,mf(i))+Pstar(:,mm+i);
0074             a        = a + Ki*v(i)/Fi;
0075             Pstar     = Pstar - Ki*transpose(Ki)/Fi;
0076             lik(t)     = lik(t) + log(Fi) + v(i)*v(i)/Fi;
0077         end
0078     end    
0079     oldP         = Pstar;
0080     a             = T*a;
0081     Pstar         = T*Pstar*transpose(T) + QQ;
0082     notsteady     = ~(max(max(abs(Pstar-oldP)))<crit);
0083 end
0084 while t < smpl
0085     t = t+1;
0086     for i=1:pp
0087         v(i) = Y(i,t) - a(mf(i)) - trend(i,t) - a(mm+i);
0088         Fi   = Pstar(mf(i),mf(i))+Pstar(mm+i,mm+i);
0089         if Fi > crit
0090             Ki         = Pstar(:,mf(i))+Pstar(:,mm+i);
0091             a         = a + Ki*v(i)/Fi;
0092             Pstar     = Pstar - Ki*transpose(Ki)/Fi;
0093             lik(t)     = lik(t) + log(Fi) + v(i)*v(i)/Fi;
0094         end
0095     end    
0096     a = T*a;
0097 end
0098 LIK = .5*(sum(lik(start:end))-(start-1)*lik(smpl+1)/smpl);

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003