2014-10-20 16:18:54 +02:00
function DynareResults = initial_estimation_checks ( objective_function,xparam1,DynareDataset,DatasetInfo,Model,EstimatedParameters,DynareOptions,BayesInfo,BoundsInfo,DynareResults)
2016-03-25 20:20:28 +01:00
% function DynareResults = initial_estimation_checks(objective_function,xparam1,DynareDataset,DatasetInfo,Model,EstimatedParameters,DynareOptions,BayesInfo,BoundsInfo,DynareResults)
2008-01-21 13:17:46 +01:00
% Checks data (complex values, ML evaluation, initial values, BK conditions,..)
2011-09-19 16:38:38 +02:00
%
2008-01-21 13:17:46 +01:00
% INPUTS
2013-11-06 08:26:22 +01:00
% objective_function [function handle] of the objective function
% xparam1: [vector] of parameters to be estimated
2014-06-16 17:41:59 +02:00
% DynareDataset: [dseries] object storing the dataset
% DataSetInfo: [structure] storing informations about the sample.
2013-11-06 08:26:22 +01:00
% Model: [structure] decribing the model
% EstimatedParameters [structure] characterizing parameters to be estimated
% DynareOptions [structure] describing the options
% BayesInfo [structure] describing the priors
2016-03-25 20:20:28 +01:00
% BoundsInfo [structure] containing prior bounds
2013-11-06 08:26:22 +01:00
% DynareResults [structure] storing the results
2011-09-19 16:38:38 +02:00
%
2008-01-21 13:17:46 +01:00
% OUTPUTS
2011-10-12 21:46:50 +02:00
% DynareResults structure of temporary results
2011-09-19 16:38:38 +02:00
%
2008-01-21 13:17:46 +01:00
% SPECIAL REQUIREMENTS
% none
2016-03-11 16:22:42 +01:00
% Copyright (C) 2003-2016 Dynare Team
2008-08-01 14:40:33 +02:00
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2008-01-21 13:17:46 +01:00
2015-10-11 10:49:15 +02:00
%get maximum number of simultaneously observed variables for stochastic
%singularity check
maximum_number_non_missing_observations = max ( sum ( ~ isnan ( DynareDataset . data ) , 2 ) ) ;
2015-10-20 15:49:07 +02:00
if DynareOptions . order > 1 && any ( any ( isnan ( DynareDataset . data ) ) )
error ( ' initial_estimation_checks:: particle filtering does not support missing observations' )
end
2015-10-11 10:49:15 +02:00
if maximum_number_non_missing_observations > Model . exo_nbr + EstimatedParameters . nvn
2012-06-14 14:49:10 +02:00
error ( [ ' initial_estimation_checks:: Estimation can' ' t take place because there are less declared shocks than observed variables!' ] )
end
2014-06-16 17:41:59 +02:00
2015-10-11 10:49:15 +02:00
if maximum_number_non_missing_observations > length ( find ( diag ( Model . Sigma_e ) ) ) + EstimatedParameters . nvn
2012-06-14 14:49:10 +02:00
error ( [ ' initial_estimation_checks:: Estimation can' ' t take place because too many shocks have been calibrated with a zero variance!' ] )
2009-12-16 18:17:34 +01:00
end
2015-05-20 10:10:31 +02:00
if ~ ( strcmpi ( DynareOptions . proposal_distribution , ' rand_multivariate_student' ) || ...
strcmpi ( DynareOptions . proposal_distribution , ' rand_multivariate_normal' ) )
2015-05-19 12:08:42 +02:00
error ( [ ' initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ...
' rand_multivariate_student or rand_multivariate_normal as options' ] ) ;
end
if DynareOptions . student_degrees_of_freedom < = 0
error ( ' initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument' ) ;
end
2015-05-14 14:26:54 +02:00
if DynareOptions . TaRB . use_TaRB && ( DynareOptions . TaRB . new_block_probability < 0 || DynareOptions . TaRB . new_block_probability > 1 )
error ( [ ' initial_estimation_checks:: The tarb_new_block_probability must be between 0 and 1!' ] )
end
2016-03-06 21:19:17 +01:00
if ( any ( BayesInfo . pshape > 0 ) && DynareOptions . mh_replic ) && DynareOptions . mh_nblck < 1
error ( [ ' initial_estimation_checks:: Bayesian estimation cannot be conducted with mh_nblocks=0.' ] )
end
2015-02-11 12:58:36 +01:00
old_steady_params = Model . params ; %save initial parameters for check if steady state changes param values
% % check if steady state solves static model (except if diffuse_filter == 1)
[ DynareResults . steady_state , new_steady_params ] = evaluate_steady_state ( DynareResults . steady_state , Model , DynareOptions , DynareResults , DynareOptions . diffuse_filter == 0 ) ;
2015-04-20 16:45:51 +02:00
if isfield ( EstimatedParameters , ' param_vals' ) && ~ isempty ( EstimatedParameters . param_vals )
2015-03-01 13:36:21 +01:00
%check whether steady state file changes estimated parameters
Model_par_varied = Model ; %store Model structure
Model_par_varied . params ( EstimatedParameters . param_vals ( : , 1 ) ) = Model_par_varied . params ( EstimatedParameters . param_vals ( : , 1 ) ) * 1.01 ; %vary parameters
[ junk , new_steady_params_2 ] = evaluate_steady_state ( DynareResults . steady_state , Model_par_varied , DynareOptions , DynareResults , DynareOptions . diffuse_filter == 0 ) ;
2015-02-11 12:58:36 +01:00
2015-03-01 13:36:21 +01:00
changed_par_indices = find ( ( old_steady_params ( EstimatedParameters . param_vals ( : , 1 ) ) - new_steady_params ( EstimatedParameters . param_vals ( : , 1 ) ) ) ...
| ( Model_par_varied . params ( EstimatedParameters . param_vals ( : , 1 ) ) - new_steady_params_2 ( EstimatedParameters . param_vals ( : , 1 ) ) ) ) ;
2015-02-11 12:58:36 +01:00
2015-03-01 13:36:21 +01:00
if ~ isempty ( changed_par_indices )
fprintf ( ' \nThe steady state file internally changed the values of the following estimated parameters:\n' )
2015-10-28 15:34:14 +01:00
disp ( Model . param_names ( EstimatedParameters . param_vals ( changed_par_indices , 1 ) , : ) ) ;
2015-03-01 13:36:21 +01:00
fprintf ( ' This will override the parameter values drawn from the proposal density and may lead to wrong results.\n' )
fprintf ( ' Check whether this is really intended.\n' )
warning ( ' The steady state file internally changes the values of the estimated parameters.' )
end
2015-02-11 12:58:36 +01:00
end
2012-03-30 11:12:59 +02:00
2013-11-06 08:26:22 +01:00
if any ( BayesInfo . pshape ) % if Bayesian estimation
nvx = EstimatedParameters . nvx ;
if nvx && any ( BayesInfo . p3 ( 1 : nvx ) < 0 )
warning ( ' Your prior allows for negative standard deviations for structural shocks. Due to working with variances, Dynare will be able to continue, but it is recommended to change your prior.' )
end
offset = nvx ;
nvn = EstimatedParameters . nvn ;
if nvn && any ( BayesInfo . p3 ( 1 + offset : offset + nvn ) < 0 )
warning ( ' Your prior allows for negative standard deviations for measurement error. Due to working with variances, Dynare will be able to continue, but it is recommended to change your prior.' )
end
offset = nvx + nvn ;
ncx = EstimatedParameters . ncx ;
if ncx && ( any ( BayesInfo . p3 ( 1 + offset : offset + ncx ) < - 1 ) || any ( BayesInfo . p4 ( 1 + offset : offset + ncx ) > 1 ) )
warning ( ' Your prior allows for correlations between measurement errors larger than +-1 and will not integrate to 1 due to truncation. Please change your prior' )
end
offset = nvx + nvn + ncx ;
ncn = EstimatedParameters . ncn ;
if ncn && ( any ( BayesInfo . p3 ( 1 + offset : offset + ncn ) < - 1 ) || any ( BayesInfo . p4 ( 1 + offset : offset + ncn ) > 1 ) )
warning ( ' Your prior allows for correlations between structural shocks larger than +-1 and will not integrate to 1 due to truncation. Please change your prior' )
end
end
2014-09-17 20:09:33 +02:00
% display warning if some parameters are still NaN
2014-09-25 09:02:02 +02:00
test_for_deep_parameters_calibration ( Model ) ;
2014-09-17 20:09:33 +02:00
[ lnprior , junk1 , junk2 , info ] = priordens ( xparam1 , BayesInfo . pshape , BayesInfo . p6 , BayesInfo . p7 , BayesInfo . p3 , BayesInfo . p4 ) ;
if info
fprintf ( ' The prior density evaluated at the initial values is Inf for the following parameters: %s\n' , BayesInfo . name { info , 1 } )
error ( ' The initial value of the prior is -Inf' )
end
2013-11-06 08:26:22 +01:00
2012-03-30 11:12:59 +02:00
% Evaluate the likelihood.
2012-08-21 15:46:35 +02:00
ana_deriv = DynareOptions . analytic_derivation ;
DynareOptions . analytic_derivation = 0 ;
2015-05-27 18:06:48 +02:00
if ~ isequal ( DynareOptions . mode_compute , 11 ) || ...
( isequal ( DynareOptions . mode_compute , 11 ) && isequal ( DynareOptions . order , 1 ) )
2015-10-09 14:19:34 +02:00
[ fval , junk1 , junk2 , a , b , c , d ] = feval ( objective_function , xparam1 , DynareDataset , DatasetInfo , DynareOptions , Model , EstimatedParameters , BayesInfo , BoundsInfo , DynareResults ) ;
2014-08-29 15:36:07 +02:00
else
2015-10-09 14:19:34 +02:00
b = 0 ;
2014-08-29 15:36:07 +02:00
fval = 0 ;
end
2014-09-20 19:57:43 +02:00
if DynareOptions . debug
DynareResults . likelihood_at_initial_parameters = fval ;
end
2012-08-21 15:46:35 +02:00
DynareOptions . analytic_derivation = ana_deriv ;
2011-10-12 21:46:50 +02:00
2015-10-09 14:19:34 +02:00
if DynareOptions . dsge_var || strcmp ( func2str ( objective_function ) , ' non_linear_dsge_likelihood' )
info = b ;
2015-10-06 11:08:58 +02:00
else
2015-10-09 14:19:34 +02:00
info = d ;
2012-03-30 11:12:59 +02:00
end
2012-05-31 14:42:52 +02:00
% if DynareOptions.mode_compute==5
% if ~strcmp(func2str(objective_function),'dsge_likelihood')
% error('Options mode_compute=5 is not compatible with non linear filters or Dsge-VAR models!')
% end
% end
2012-06-13 15:47:01 +02:00
if isnan ( fval )
error ( ' The initial value of the likelihood is NaN' )
elseif imag ( fval )
error ( ' The initial value of the likelihood is complex' )
end
2005-02-18 20:54:39 +01:00
2009-12-16 18:17:34 +01:00
if info ( 1 ) > 0
disp ( ' Error in computing likelihood for initial parameter values' )
2013-06-12 10:54:33 +02:00
print_info ( info , DynareOptions . noprint , DynareOptions )
2009-12-16 18:17:34 +01:00
end
2014-06-15 12:26:36 +02:00
if DynareOptions . prefilter == 1
if ( ~ DynareOptions . loglinear && any ( abs ( DynareResults . steady_state ( BayesInfo . mfys ) ) > 1e-9 ) ) || ( DynareOptions . loglinear && any ( abs ( log ( DynareResults . steady_state ( BayesInfo . mfys ) ) ) > 1e-9 ) )
disp ( [ ' You are trying to estimate a model with a non zero steady state for the observed endogenous' ] )
disp ( [ ' variables using demeaned data!' ] )
error ( ' You should change something in your mod file...' )
end
2009-12-16 18:17:34 +01:00
end
2014-08-29 15:36:07 +02:00
if ~ isequal ( DynareOptions . mode_compute , 11 )
disp ( [ ' Initial value of the log posterior (or likelihood): ' num2str ( - fval ) ] ) ;
end