Home > matlab > model_diagnostics.m

model_diagnostics

PURPOSE ^

function model_diagnostics(M_,options_,oo_)

SYNOPSIS ^

function model_diagnostics(M_,options_,oo_)

DESCRIPTION ^

 function model_diagnostics(M_,options_,oo_)
   computes various diagnostics on the model 
 INPUTS
   M_         [matlab structure] Definition of the model.           
   options_   [matlab structure] Global options.
   oo_        [matlab structure] Results 
    
 OUTPUTS
   none
    
 ALGORITHM
   ...
    
 SPECIAL REQUIREMENTS
   none.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function model_diagnostics(M_,options_,oo_)
0002 % function model_diagnostics(M_,options_,oo_)
0003 %   computes various diagnostics on the model
0004 % INPUTS
0005 %   M_         [matlab structure] Definition of the model.
0006 %   options_   [matlab structure] Global options.
0007 %   oo_        [matlab structure] Results
0008 %
0009 % OUTPUTS
0010 %   none
0011 %
0012 % ALGORITHM
0013 %   ...
0014 %
0015 % SPECIAL REQUIREMENTS
0016 %   none.
0017 %
0018 
0019 % Copyright (C) 1996-2011 Dynare Team
0020 %
0021 % This file is part of Dynare.
0022 %
0023 % Dynare is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % Dynare is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 global jacob
0037 
0038 endo_nbr = M_.endo_nbr;
0039 endo_names = M_.endo_names;
0040 lead_lag_incidence = M_.lead_lag_incidence;
0041 maximum_lag = M_.maximum_lag;
0042 maximum_lead = M_.maximum_lead;
0043 
0044 %
0045 % missing variables at the current period
0046 %
0047 k = find(lead_lag_incidence(maximum_lag+1,:)==0);
0048 if ~isempty(k)
0049     disp(['The following endogenous variables aren''t present at ' ...
0050           'the current period in the model:'])
0051     for i=1:length(k)
0052         disp(endo_names(k(i),:))
0053     end
0054 end
0055 
0056 %
0057 % check steady state
0058 %
0059 info = 0;
0060 
0061 it_ = M_.maximum_lag + 1 ;
0062 
0063 if M_.exo_nbr == 0
0064     oo_.exo_steady_state = [] ;
0065 end
0066 
0067 % check if ys is steady state
0068 tempex = oo_.exo_simul;
0069 oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+M_.maximum_lead+1,1);
0070 if M_.exo_det_nbr > 0 
0071     tempexdet = oo_.exo_det_simul;
0072     oo_.exo_det_simul = repmat(oo_.exo_det_steady_state',M_.maximum_lag+M_.maximum_lead+1,1);
0073 end
0074 dr.ys = oo_.steady_state;
0075 check1 = 0;
0076 % testing for steadystate file
0077 fh = str2func([M_.fname '_static']);
0078 if options_.steadystate_flag
0079     [ys,check1] = feval([M_.fname '_steadystate'],dr.ys,...
0080                         [oo_.exo_steady_state; oo_.exo_det_steady_state]);
0081     M_.params = evalin('base','M_.params;');
0082     if size(ys,1) < M_.endo_nbr 
0083         if length(M_.aux_vars) > 0
0084             ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,...
0085                                                         M_.fname,...
0086                                                         oo_.exo_steady_state,...
0087                                                         oo_.exo_det_steady_state,...
0088                                                         M_.params,...
0089                                                         options_.bytecode);
0090         else
0091             error([M_.fname '_steadystate.m doesn''t match the model']);
0092         end
0093     end
0094     dr.ys = ys;
0095 else
0096     % testing if ys isn't a steady state or if we aren't computing Ramsey policy
0097     if  options_.ramsey_policy == 0
0098         if options_.linear == 0
0099             % nonlinear models
0100             if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ...
0101                                     oo_.exo_det_steady_state], M_.params))) > options_.dynatol.f
0102                 [ys,check1] = dynare_solve(fh,dr.ys,1,...
0103                                            [oo_.exo_steady_state; ...
0104                                     oo_.exo_det_steady_state], ...
0105                                            M_.params);
0106                 if ~check1
0107                     dr.ys = ys;
0108                 end
0109             end
0110         else
0111             % linear models
0112             [fvec,jacob] = feval(fh,dr.ys,[oo_.exo_steady_state;...
0113                                 oo_.exo_det_steady_state], M_.params);
0114             if max(abs(fvec)) > 1e-12
0115                 dr.ys = dr.ys-jacob\fvec;
0116             end
0117         end
0118     end
0119 end
0120 % testing for problem
0121 if check1
0122     disp('model diagnostic can''t obtain the steady state')
0123 end
0124 
0125 if ~isreal(dr.ys)
0126     disp(['model diagnostic obtains a steady state with complex ' ...
0127           'numbers'])
0128     return
0129 end
0130 
0131 %
0132 % singular Jacobian of static model
0133 %
0134 
0135 [res,jacob]=feval(fh,dr.ys,[oo_.exo_steady_state; oo_.exo_det_steady_state], ...
0136                   M_.params);
0137 rank_jacob = rank(jacob);
0138 if rank_jacob < endo_nbr
0139     disp(['model_diagnostic: the Jacobian of the static model is ' ...
0140           'singular'])
0141     disp(['there is ' num2str(endo_nbr-rank_jacob) ...
0142           ' colinear relationships between the variables and the equations'])
0143     ncol = null(jacob);
0144     n_rel = size(ncol,2);
0145     for i = 1:n_rel
0146         if n_rel  > 1
0147             disp(['Relation ' int2str(i)])
0148         end
0149         disp('Colinear variables:')
0150         for j=1:10
0151             k = find(abs(ncol(:,i)) > 10^-j);
0152             if max(abs(jacob(:,k)*ncol(k,i))) < 1e-6
0153                 break
0154             end
0155         end
0156         disp(endo_names(k,:))
0157     end
0158     neq = null(jacob');
0159     n_rel = size(neq,2);
0160     for i = 1:n_rel
0161         if n_rel  > 1
0162             disp(['Relation ' int2str(i)])
0163         end
0164         disp('Colinear equations')
0165         for j=1:10
0166             k = find(abs(neq(:,i)) > 10^-j);
0167             if max(abs(jacob(k,:)'*neq(k,i))) < 1e-6
0168                 break
0169             end
0170         end
0171         disp(k')
0172     end
0173 end
0174

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005