v4: fixed bug concerning handling of filter decomposition (decomp) in DiffuseKalmanSmoother1_Z. and DsgeSmoother.m
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1814 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
b99d608b7e
commit
6352e90b26
|
@ -1,4 +1,4 @@
|
|||
function [alphahat,etahat,a,aK,P,PK,d] = DiffuseKalmanSmoother1_Z(T,Z,R,Q,Pinf1,Pstar1,Y,pp,mm,smpl)
|
||||
function [alphahat,etahat,a,aK,P,PK,d,decomp] = DiffuseKalmanSmoother1_Z(T,Z,R,Q,Pinf1,Pstar1,Y,pp,mm,smpl)
|
||||
|
||||
% function [alphahat,etahat,a, aK] = DiffuseKalmanSmoother1(T,Z,R,Q,Pinf1,Pstar1,Y,pp,mm,smpl)
|
||||
% Computes the diffuse kalman smoother without measurement error, in the case of a non-singular var-cov matrix
|
||||
|
@ -27,6 +27,7 @@ function [alphahat,etahat,a,aK,P,PK,d] = DiffuseKalmanSmoother1_Z(T,Z,R,Q,Pinf1,
|
|||
% matrices (meaningless for periods 1:d)
|
||||
% d: number of periods where filter remains in diffuse part
|
||||
% (should be equal to the order of integration of the model)
|
||||
% decomp: decomposition of the effect of shocks on filtered values
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% See "Filtering and Smoothing of State Vector for Diffuse State Space
|
||||
|
@ -47,6 +48,7 @@ function [alphahat,etahat,a,aK,P,PK,d] = DiffuseKalmanSmoother1_Z(T,Z,R,Q,Pinf1,
|
|||
global options_
|
||||
|
||||
d = 0;
|
||||
decomp = [];
|
||||
nk = options_.nk;
|
||||
spinf = size(Pinf1);
|
||||
spstar = size(Pstar1);
|
||||
|
@ -176,3 +178,29 @@ else
|
|||
alphahat(:,1) = a(:,1) + P(:,:,1)*r0;
|
||||
etahat(:,1) = QRt*r(:,1);
|
||||
end
|
||||
|
||||
if nargout > 7
|
||||
decomp = zeros(nk,mm,rr,smpl+nk);
|
||||
ZRQinv = inv(Z*QQ*Z');
|
||||
for t = d:smpl
|
||||
ri_d = zeros(mm,1);
|
||||
for i=pp:-1:1
|
||||
if Fi(i,t) > crit
|
||||
ri_d = Z(i,:)'/Fi(i,t)*v(i,t)+Li(:,:,i,t)'*ri_d;
|
||||
end
|
||||
end
|
||||
|
||||
% calculate eta_tm1t
|
||||
eta_tm1t = QRt*ri_d;
|
||||
% calculate decomposition
|
||||
Ttok = eye(mm,mm);
|
||||
for h = 1:nk
|
||||
for j=1:rr
|
||||
eta=zeros(rr,1);
|
||||
eta(j) = eta_tm1t(j);
|
||||
decomp(h,:,j,t+h) = Ttok*P1(:,:,t)*Z'*ZRQinv*Z*R*eta;
|
||||
end
|
||||
Ttok = T*Ttok;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@ function [alphahat,etahat,a1,P,aK,PK,d,decomp] = DiffuseKalmanSmoother3_Z(T,Z,R,
|
|||
global options_
|
||||
|
||||
d = 0;
|
||||
|
||||
decomp = [];
|
||||
nk = options_.nk;
|
||||
spinf = size(Pinf1);
|
||||
spstar = size(Pstar1);
|
||||
|
@ -319,4 +319,4 @@ if nargout > 7
|
|||
Ttok = T*Ttok;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -183,15 +183,22 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,d,
|
|||
if options_.kalman_algo == 1
|
||||
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother1(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
||||
if all(alphahat(:)==0)
|
||||
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
||||
options_.kalman_algo = 3;
|
||||
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
||||
end
|
||||
elseif options_.kalman_algo == 3
|
||||
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
||||
elseif options_.kalman_algo == 4 | options_.kalman_algo == 5
|
||||
data1 = Y - trend;
|
||||
if options_.kalman_algo == 4
|
||||
[alphahat,etahat,ahat,P,aK,PK,d] = DiffuseKalmanSmoother1_Z(ST, ...
|
||||
[alphahat,etahat,ahat,P,aK,PK,d,decomp] = DiffuseKalmanSmoother1_Z(ST, ...
|
||||
Z,R1,Q,Pinf,Pstar,data1,nobs,np,smpl);
|
||||
if all(alphahat(:)==0)
|
||||
options_.kalman_algo = 5;
|
||||
[alphahat,etahat,ahat,P,aK,PK,d,decomp] = DiffuseKalmanSmoother3_Z(ST, ...
|
||||
Z,R1,Q,Pinf,Pstar, ...
|
||||
data1,nobs,np,smpl);
|
||||
end
|
||||
else
|
||||
[alphahat,etahat,ahat,P,aK,PK,d,decomp] = DiffuseKalmanSmoother3_Z(ST, ...
|
||||
Z,R1,Q,Pinf,Pstar,data1,nobs,np,smpl);
|
||||
|
|
Loading…
Reference in New Issue