Harmonize FilteredVariables with Updated and Smoothed ones, by adding steady state to stored values, both point estimate and MCMC
(cherry picked from commit fd0d7d6d27a7937b135521c4dd76d7fa242d89ab)time-shift
parent
7621ebb5ea
commit
bf293396b6
|
@ -147,8 +147,13 @@ end
|
|||
if ~isempty(options_.nk) && options_.nk ~= 0 && ~isempty(bayestopt_)
|
||||
if ~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.pshape> 0) && options_.load_mh_file)) %no Bayesian estimation
|
||||
positions_in_decision_order=oo_.dr.inv_order_var(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list));
|
||||
if options_.loglinear == 1 %logged steady state must be used
|
||||
constant_all_variables=log(oo_.dr.ys(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list)));
|
||||
elseif options_.loglinear == 0 %unlogged steady state must be used
|
||||
constant_all_variables=oo_.dr.ys(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list));
|
||||
end
|
||||
if ~(options_.selected_variables_only && ~(options_.forecast > 0)) %happens only when selected_variables_only is not used
|
||||
oo_.FilteredVariablesKStepAhead(:,positions_in_decision_order,:)=oo_.FilteredVariablesKStepAhead;
|
||||
oo_.FilteredVariablesKStepAhead(:,positions_in_decision_order,:)=oo_.FilteredVariablesKStepAhead-constant_all_variables;
|
||||
if ~isempty(PK) %get K-step ahead variances
|
||||
oo_.FilteredVariablesKStepAheadVariances(:,positions_in_decision_order,positions_in_decision_order,:)=oo_.FilteredVariablesKStepAheadVariances;
|
||||
end
|
||||
|
@ -184,4 +189,4 @@ if ~isempty(M_.osr.variable_indices)
|
|||
end
|
||||
if ~isempty(M_.osr.param_names)
|
||||
evalin('base','osr_params_=char(M_.osr.param_names)')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -169,7 +169,7 @@ if ~loadSA,
|
|||
rmse_mode = sqrt(mean((yobs(istart:end,:)-y0(istart:end,:)).^2));
|
||||
r2_mode = 1-sum((yobs(istart:end,:)-y0(istart:end,:)).^2)./sum(yobs(istart:end,:).^2);
|
||||
end
|
||||
y0=yss*0;
|
||||
y0=-yss;
|
||||
nbb=0;
|
||||
for j=1:length(filfilt),
|
||||
load([DirectoryName filesep M_.fname '_filter_step_ahead',num2str(j),'.mat']);
|
||||
|
|
|
@ -237,14 +237,26 @@ for b=fpar:B
|
|||
end
|
||||
if naK
|
||||
%filtered variable E_t(y_t+k) requires to shift trend by k periods
|
||||
%write percentage deviation of variables into declaration order
|
||||
stock_filter_step_ahead(:,dr.order_var,:,irun(4)) = aK(options_.filter_step_ahead,1:endo_nbr,:);
|
||||
%write variables into declaration order
|
||||
if options_.loglinear %reads values from smoother results, which are in dr-order and put them into declaration order
|
||||
constant_part=repmat(log(SteadyState(dr.order_var))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)])
|
||||
else
|
||||
constant_part=repmat(SteadyState(dr.order_var)',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
|
||||
end
|
||||
|
||||
stock_filter_step_ahead(:,dr.order_var,:,irun(4)) = aK(options_.filter_step_ahead,1:endo_nbr,:) + ...
|
||||
constant_part;
|
||||
|
||||
%now add trend and constant to filtered variables
|
||||
%now add trend to observables
|
||||
for ii=1:length(options_.filter_step_ahead)
|
||||
stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))...
|
||||
+repmat(constant_part(:,1),1,gend+max(options_.filter_step_ahead))... %constant
|
||||
+[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend
|
||||
if options_.prefilter
|
||||
stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))...
|
||||
+repmat(mean_correction(:,1),1,gend+max(options_.filter_step_ahead))... %constant correction
|
||||
+[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend
|
||||
else
|
||||
stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))...
|
||||
+[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -434,10 +446,10 @@ if RemoteFlag==1,
|
|||
OutputFileName_filter_step_ahead;
|
||||
OutputFileName_param;
|
||||
OutputFileName_forc_mean;
|
||||
OutputFileName_forc_point
|
||||
OutputFileName_filter_covar
|
||||
OutputFileName_trend_coeff
|
||||
OutputFileName_smoothed_trend
|
||||
OutputFileName_forc_point;
|
||||
OutputFileName_filter_covar;
|
||||
OutputFileName_trend_coeff;
|
||||
OutputFileName_smoothed_trend;
|
||||
OutputFileName_smoothed_constant];
|
||||
end
|
||||
|
||||
|
|
|
@ -120,9 +120,16 @@ end
|
|||
%get indices of smoothed variables
|
||||
i_endo_in_bayestopt_smoother_varlist = bayestopt_.smoother_saved_var_list;
|
||||
i_endo_in_dr_matrices=bayestopt_.smoother_var_list(i_endo_in_bayestopt_smoother_varlist);
|
||||
if ~isempty(options_.nk) && options_.nk ~= 0
|
||||
%write deviations from steady state, add constant for observables later
|
||||
oo_.FilteredVariablesKStepAhead = aK(options_.filter_step_ahead,i_endo_in_dr_matrices,:);
|
||||
if ~isempty(options_.nk) && options_.nk ~= 0
|
||||
%% Compute constant
|
||||
i_endo_declaration_order = oo_.dr.order_var(i_endo_in_dr_matrices); %get indices of smoothed variables in name vector
|
||||
if options_.loglinear == 1 %logged steady state must be used
|
||||
constant_all_variables=repmat(log(ys(i_endo_declaration_order))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
|
||||
elseif options_.loglinear == 0 %unlogged steady state must be used
|
||||
constant_all_variables=repmat((ys(i_endo_declaration_order))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
|
||||
end
|
||||
% add constant
|
||||
oo_.FilteredVariablesKStepAhead = aK(options_.filter_step_ahead,i_endo_in_dr_matrices,:)+constant_all_variables;
|
||||
if ~isempty(PK) %get K-step ahead variances
|
||||
oo_.FilteredVariablesKStepAheadVariances = ...
|
||||
PK(options_.filter_step_ahead,i_endo_in_dr_matrices,i_endo_in_dr_matrices,:);
|
||||
|
@ -145,7 +152,7 @@ for i_endo_in_bayestopt_smoother_varlist=bayestopt_.smoother_saved_var_list'
|
|||
oo_.Smoother.Constant.(deblank(M_.endo_names(i_endo_declaration_order,:)))=constant_current_variable;
|
||||
oo_.SmoothedVariables.(deblank(M_.endo_names(i_endo_declaration_order,:)))=atT(i_endo_in_dr,:)'+constant_current_variable;
|
||||
if ~isempty(options_.nk) && options_.nk > 0 && ~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.pshape> 0) && options_.load_mh_file))
|
||||
oo_.FilteredVariables.(deblank(M_.endo_names(i_endo_declaration_order,:)))=squeeze(aK(1,i_endo_in_dr,2:end-(options_.nk-1)));
|
||||
oo_.FilteredVariables.(deblank(M_.endo_names(i_endo_declaration_order,:)))=squeeze(aK(1,i_endo_in_dr,2:end-(options_.nk-1)))+constant_current_variable;
|
||||
end
|
||||
oo_.UpdatedVariables.(deblank(M_.endo_names(i_endo_declaration_order,:)))=updated_variables(i_endo_in_dr,:)'+constant_current_variable;
|
||||
end
|
||||
|
@ -212,4 +219,4 @@ if ~isequal(M_.H,0)
|
|||
for meas_error_iter=1:length(options_.varobs)
|
||||
oo_.SmoothedMeasurementErrors.(options_.varobs{meas_error_iter})= measurement_error(meas_error_iter,:)';
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue