Skip to content
Snippets Groups Projects
Commit a18b0717 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Fixed shocks decomposition bug.

(cherry picked from commit 68e7a310)
parent 608c82fd
No related branches found
No related tags found
No related merge requests found
...@@ -43,8 +43,7 @@ function oo = evaluate_smoother(parameters) ...@@ -43,8 +43,7 @@ function oo = evaluate_smoother(parameters)
global options_ M_ bayestopt_ oo_ global options_ M_ bayestopt_ oo_
persistent load_data persistent dataset_
persistent gend data data_index number_of_observations no_more_missing_observations
if nargin==0 if nargin==0
parameters = 'posterior_mode'; parameters = 'posterior_mode';
...@@ -79,43 +78,22 @@ if ischar(parameters) ...@@ -79,43 +78,22 @@ if ischar(parameters)
end end
end end
if isempty(load_data) if isempty(dataset_)
% Get the data. % Load and transform data.
n_varobs = size(options_.varobs,1); transformation = [];
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); if options_.loglinear && ~options_.logdata
options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1); transformation = @log;
gend = options_.nobs; end
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); xls.sheet = options_.xls_sheet;
% Transform the data. xls.range = options_.xls_range;
if options_.loglinear
if ~options_.logdata if ~isfield(options_,'nobs')
rawdata = log(rawdata); options_.nobs = [];
end
end
% Test if the data set is real.
if ~isreal(rawdata)
error('There are complex values in the data! Probably a wrong transformation')
end
% Detrend the data.
options_.missing_data = any(any(isnan(rawdata)));
if options_.prefilter == 1
if options_.missing_data
bayestopt_.mean_varobs = zeros(n_varobs,1);
for variable=1:n_varobs
rdx = find(~isnan(rawdata(:,variable)));
m = mean(rawdata(rdx,variable));
rawdata(rdx,variable) = rawdata(rdx,variable)-m;
bayestopt_.mean_varobs(variable) = m;
end
else
bayestopt_.mean_varobs = mean(rawdata,1)';
rawdata = rawdata-repmat(bayestopt_.mean_varobs',gend,1);
end
end end
data = transpose(rawdata);
% Handle the missing observations. dataset_ = initialize_dataset(options_.datafile,options_.varobs,options_.first_obs,options_.nobs,transformation,options_.prefilter,xls);
[data_index,number_of_observations,no_more_missing_observations] = describe_missing_data(data,gend,n_varobs); options_.nobs = dataset_.info.ntobs;
missing_value = ~(number_of_observations == gend*n_varobs);
% Determine if a constant is needed. % Determine if a constant is needed.
if options_.steadystate_flag% if the *_steadystate.m file is provided. if options_.steadystate_flag% if the *_steadystate.m file is provided.
[ys,tchek] = feval([M_.fname '_steadystate'],... [ys,tchek] = feval([M_.fname '_steadystate'],...
...@@ -143,15 +121,15 @@ if isempty(load_data) ...@@ -143,15 +121,15 @@ if isempty(load_data)
else else
options_.noconstant = 0; options_.noconstant = 0;
end end
load_data = 1;
end end
pshape_original = bayestopt_.pshape; pshape_original = bayestopt_.pshape;
bayestopt_.pshape = Inf(size(bayestopt_.pshape)); bayestopt_.pshape = Inf(size(bayestopt_.pshape));
clear('priordens')% clear('priordens')
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp] = ...
DsgeSmoother(parameters,dataset_.info.ntobs,dataset_.data,dataset_.missing.aindex,dataset_.missing.state);
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp] ...
= DsgeSmoother(parameters,gend,data,data_index,missing_value);
oo.Smoother.SteadyState = ys; oo.Smoother.SteadyState = ys;
oo.Smoother.TrendCoeffs = trend_coeff; oo.Smoother.TrendCoeffs = trend_coeff;
if options_.filter_covariance if options_.filter_covariance
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment