corecting logic for selecting univariate diffuse filter and dealing
with correlated measurement errorstime-shift
parent
f0d1f033b0
commit
cfb5114d41
|
@ -358,6 +358,7 @@ end
|
|||
|
||||
|
||||
diffuse_periods = 0;
|
||||
correlated_errors_have_been_checked = 0;
|
||||
switch DynareOptions.lik_init
|
||||
case 1% Standard initialization with the steady state of the state equation.
|
||||
if kalman_algo~=2
|
||||
|
@ -378,10 +379,14 @@ switch DynareOptions.lik_init
|
|||
a = zeros(mm,1);
|
||||
Zflag = 0;
|
||||
case 3% Diffuse Kalman filter (Durbin and Koopman)
|
||||
if kalman_algo ~= 4
|
||||
% Use standard kalman filter except if the univariate filter is explicitely choosen.
|
||||
if kalman_algo == 0
|
||||
kalman_algo = 3;
|
||||
elseif ~((kalman_algo == 3) || (kalman_algo == 4))
|
||||
error(['diffuse filter: options_.kalman_algo can only be equal ' ...
|
||||
'to 0 (default), 3 or 4'])
|
||||
end
|
||||
|
||||
[Z,T,R,QT,Pstar,Pinf] = schur_statespace_transformation(Z,T,R,Q,DynareOptions.qz_criterium);
|
||||
Zflag = 1;
|
||||
% Run diffuse kalman filter on first periods.
|
||||
|
@ -403,12 +408,10 @@ switch DynareOptions.lik_init
|
|||
if isinf(dLIK)
|
||||
% Go to univariate diffuse filter if singularity problem.
|
||||
kalman_algo = 4;
|
||||
singularity_flag = 1;
|
||||
end
|
||||
end
|
||||
if (kalman_algo==4)
|
||||
% Univariate Diffuse Kalman Filter
|
||||
if singularity_flag
|
||||
if isequal(H,0)
|
||||
H = zeros(nobs,1);
|
||||
mmm = mm;
|
||||
|
@ -428,9 +431,11 @@ switch DynareOptions.lik_init
|
|||
end
|
||||
end
|
||||
% no need to test again for correlation elements
|
||||
singularity_flag = 0;
|
||||
end
|
||||
[dLIK,tmp,a,Pstar] = univariate_kalman_filter_d(DynareDataset.missing.aindex,DynareDataset.missing.number_of_observations,DynareDataset.missing.no_more_missing_observations, ...
|
||||
correlated_errors_have_been_checked = 1;
|
||||
|
||||
[dLIK,tmp,a,Pstar] = univariate_kalman_filter_d(DynareDataset.missing.aindex,...
|
||||
DynareDataset.missing.number_of_observations,...
|
||||
DynareDataset.missing.no_more_missing_observations, ...
|
||||
Y, 1, size(Y,2), ...
|
||||
zeros(mmm,1), Pinf, Pstar, ...
|
||||
kalman_tol, riccati_tol, DynareOptions.presample, ...
|
||||
|
@ -605,7 +610,6 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
|
|||
else
|
||||
kalman_algo = 4;
|
||||
end
|
||||
singularity_flag = 1;
|
||||
else
|
||||
if DynareOptions.lik_init==3
|
||||
LIK = LIK + dLIK;
|
||||
|
@ -613,10 +617,10 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
|
|||
end
|
||||
end
|
||||
|
||||
if ( singularity_flag || (kalman_algo==2) || (kalman_algo==4) )
|
||||
if (kalman_algo==2) || (kalman_algo==4)
|
||||
% Univariate Kalman Filter
|
||||
% resetting measurement error covariance matrix when necessary %
|
||||
if singularity_flag
|
||||
if ~correlated_errors_have_been_checked
|
||||
if isequal(H,0)
|
||||
H = zeros(nobs,1);
|
||||
mmm = mm;
|
||||
|
|
|
@ -254,6 +254,7 @@ end
|
|||
|
||||
|
||||
diffuse_periods = 0;
|
||||
correlated_errors_have_been_checked = 0;
|
||||
switch DynareOptions.lik_init
|
||||
case 1% Standard initialization with the steady state of the state equation.
|
||||
if kalman_algo~=2
|
||||
|
@ -274,10 +275,14 @@ switch DynareOptions.lik_init
|
|||
a = zeros(mm,1);
|
||||
Zflag = 0;
|
||||
case 3% Diffuse Kalman filter (Durbin and Koopman)
|
||||
if kalman_algo ~= 4
|
||||
% Use standard kalman filter except if the univariate filter is explicitely choosen.
|
||||
if kalman_algo == 0
|
||||
kalman_algo = 3;
|
||||
elseif ~((kalman_algo == 3) || (kalman_algo == 4))
|
||||
error(['diffuse filter: options_.kalman_algo can only be equal ' ...
|
||||
'to 0 (default), 3 or 4'])
|
||||
end
|
||||
|
||||
[Z,T,R,QT,Pstar,Pinf] = schur_statespace_transformation(Z,T,R,Q,DynareOptions.qz_criterium);
|
||||
Zflag = 1;
|
||||
% Run diffuse kalman filter on first periods.
|
||||
|
@ -304,7 +309,6 @@ switch DynareOptions.lik_init
|
|||
end
|
||||
if (kalman_algo==4)
|
||||
% Univariate Diffuse Kalman Filter
|
||||
if singularity_flag
|
||||
if isequal(H,0)
|
||||
H = zeros(nobs,1);
|
||||
mmm = mm;
|
||||
|
@ -324,8 +328,8 @@ switch DynareOptions.lik_init
|
|||
end
|
||||
end
|
||||
% no need to test again for correlation elements
|
||||
singularity_flag = 0;
|
||||
end
|
||||
correlated_errors_have_been_checked = 1;
|
||||
|
||||
[dLIK,dlik,a,Pstar] = univariate_kalman_filter_d(DynareDataset.missing.aindex,DynareDataset.missing.number_of_observations,DynareDataset.missing.no_more_missing_observations, ...
|
||||
Y, 1, size(Y,2), ...
|
||||
zeros(mmm,1), Pinf, Pstar, ...
|
||||
|
@ -385,10 +389,10 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
|
|||
end
|
||||
end
|
||||
|
||||
if ( singularity_flag || (kalman_algo==2) || (kalman_algo==4) )
|
||||
if (kalman_algo==2) || (kalman_algo==4)
|
||||
% Univariate Kalman Filter
|
||||
% resetting measurement error covariance matrix when necessary %
|
||||
if singularity_flag
|
||||
if ~correlated_errors_have_been_checked
|
||||
if isequal(H,0)
|
||||
H = zeros(nobs,1);
|
||||
mmm = mm;
|
||||
|
|
Loading…
Reference in New Issue