dynare/matlab/+identification/analysis.m

559 lines
35 KiB
Matlab
Raw Normal View History

function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
% [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% -------------------------------------------------------------------------
% This function wraps all identification analysis, i.e. it
% (1) wraps functions for the theoretical identification analysis based on moments (Iskrev, 2010),
% spectrum (Qu and Tkachenko, 2012), minimal system (Komunjer and Ng, 2011), information matrix,
% reduced-form solution and dynamic model derivatives (Ratto and Iskrev, 2011).
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% (2) computes the identification strength based on moments (Ratto and Iskrev, 2011)
% (3) checks which parameters are involved.
% If options_ident.order>1, then the identification analysis is based on
% Mutschler (2015), i.e. the pruned state space system and the corresponding
% moments, spectrum, reduced-form solution and dynamic model derivatives
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% =========================================================================
2011-05-02 11:32:26 +02:00
% INPUTS
% * M_ [structure] describing the model
% * options_ [structure] describing the options
% * oo_ [structure] storing the results
% * bayestopt_ [structure] describing the priors
% * estim_params_ [structure] characterizing parameters to be estimated
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * params [mc_sample_nbr by totparam_nbr]
% parameter values for identification checks
% * indpmodel [modparam_nbr by 1]
% index of model parameters for which identification is checked
% * indpstderr [stderrparam_nbr by 1]
% index of stderr parameters for which identification is checked
% * indpcorr [corrparam_nbr by 2]
% matrix of corr parmeters for which identification is checked
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * options_ident [structure]
% identification options
% * dataset_info [structure]
% various information about the dataset (descriptive statistics and missing observations) for Kalman Filter
% * prior_exist [integer]
% 1: prior exists. Identification is checked for stderr, corr and model parameters as declared in estimated_params block
% 0: prior does not exist. Identification is checked for all stderr and model parameters, but no corr parameters
% * init [integer]
2020-01-16 14:43:39 +01:00
% flag for initialization of persistent vars. This is needed if one may want to make more calls to identification in the same mod file
% * error_indicator [structure]
% boolean information on errors (1 is an error, 0 is no error) while computing the criteria stored in fields identification_strength, identification_reducedform, identification_moments, identification_minimal, identification_spectrum
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% -------------------------------------------------------------------------
2011-05-02 11:32:26 +02:00
% OUTPUTS
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * ide_moments [structure]
% identification results using theoretical moments (Iskrev, 2010; Mutschler, 2015)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * ide_spectrum [structure]
% identification results using spectrum (Qu and Tkachenko, 2012; Mutschler, 2015)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * ide_minimal [structure]
2020-01-16 14:43:39 +01:00
% identification results using theoretical mean and minimal system (Komunjer and Ng, 2011)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * ide_hess [structure]
% identification results using asymptotic Hessian (Ratto and Iskrev, 2011)
% * ide_reducedform [structure]
% identification results using steady state and reduced form solution (Ratto and Iskrev, 2011)
% * ide_dynamic [structure]
% identification results using steady state and dynamic model derivatives (Ratto and Iskrev, 2011)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * derivatives_info [structure]
2020-01-16 14:43:39 +01:00
% info about first-order perturbation derivatives, used in dsge_likelihood.m
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * info [integer]
% output from dynare_resolve
% * error_indicator [structure]
% indicator on problems
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% -------------------------------------------------------------------------
% This function is called by
% * identification.run
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% -------------------------------------------------------------------------
% This function calls
% * [M_.fname,'.dynamic']
% * dseries
% * dsge_likelihood.m
% * dyn_vech
% * identification.bruteforce
% * identification.checks
% * identification.checks_via_subsets
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * isoctave
% * identification.get_jacobians (previously getJJ)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * matlab_ver_less_than
% * prior_bounds
% * resol
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * set_all_parameters
% * simulated_moment_uncertainty
% * stoch_simul
% * vec
% =========================================================================
% Copyright © 2008-2023 Dynare Team
2011-05-02 11:32:26 +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.
%
2017-05-16 15:10:20 +02:00
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% =========================================================================
2011-05-02 11:32:26 +02:00
persistent ind_dMOMENTS ind_dREDUCEDFORM ind_dDYNAMIC
2020-01-16 14:43:39 +01:00
% persistent indices are necessary, because in a MC loop the numerical threshold
% used may provide vectors of different length, leading to crashes in MC loops
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%initialize output structures
2020-01-16 14:43:39 +01:00
ide_hess = struct(); %Identification structure based on asymptotic/simulated information matrix
ide_reducedform = struct(); %Identification structure based on steady state and reduced form solution
ide_dynamic = struct(); %Identification structure based on steady state and dynamic model derivatives
ide_moments = struct(); %Identification structure based on first two moments (Iskrev, 2010; Mutschler, 2015)
ide_spectrum = struct(); %Identification structure based on Gram matrix of Jacobian of spectral density plus Gram matrix of Jacobian of steady state (Qu and Tkachenko, 2012; Mutschler, 2015)
ide_minimal = struct(); %Identification structure based on mean and minimal system (Komunjer and Ng, 2011)
derivatives_info = struct(); %storage for first-order perturbation Jacobians used in dsge_likelihood.m
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
totparam_nbr = length(params); %number of all parameters to be checked
modparam_nbr = length(indpmodel); %number of model parameters to be checked
stderrparam_nbr = length(indpstderr); %number of stderr parameters to be checked
corrparam_nbr = size(indpcorr,1); %number of stderr parameters to be checked
indvobs = bayestopt_.mf2; %index of observable variables
2011-05-02 11:32:26 +02:00
2017-05-16 12:42:01 +02:00
if ~isempty(estim_params_)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%estimated_params block is available, so we are able to use set_all_parameters.m
M_ = set_all_parameters(params,estim_params_,M_);
end
2011-05-02 11:32:26 +02:00
%get options (see identification.run.m for description of options)
nlags = options_ident.ar;
advanced = options_ident.advanced;
replic = options_ident.replic;
periods = options_ident.periods;
max_dim_cova_group = options_ident.max_dim_cova_group;
normalize_jacobians = options_ident.normalize_jacobians;
checks_via_subsets = options_ident.checks_via_subsets;
tol_deriv = options_ident.tol_deriv;
tol_rank = options_ident.tol_rank;
tol_sv = options_ident.tol_sv;
error_indicator.identification_strength=0;
error_indicator.identification_reducedform=0;
error_indicator.identification_moments=0;
error_indicator.identification_minimal=0;
error_indicator.identification_spectrum=0;
2017-05-16 15:10:20 +02:00
%Compute linear approximation and fill dr structure
[oo_.dr,info,M_.params] = compute_decision_rules(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
2011-05-02 11:32:26 +02:00
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if info(1) == 0 %no errors in solution
2020-01-16 14:43:39 +01:00
% Compute parameter Jacobians for identification analysis
[~, ~, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = identification.get_jacobians(estim_params_, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
if isempty(dMINIMAL)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% Komunjer and Ng is not computed if (1) minimality conditions are not fullfilled or (2) there are more shocks and measurement errors than observables, so we need to reset options
error_indicator.identification_minimal = 1;
%options_ident.no_identification_minimal = 1;
2011-05-02 11:32:26 +02:00
end
2017-05-16 12:42:01 +02:00
if init
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%check stationarity
if ~options_ident.no_identification_moments
if any(any(isnan(MOMENTS)))
if options_.diffuse_filter == 1 % use options_ as it inherits diffuse_filter from options_ident if set by user
error('There are NaN''s in the theoretical moments. Make sure that for non-stationary models stationary transformations of non-stationary observables are used for checking identification. [TIP: use first differences].')
else
error('There are NaN''s in the theoretical moments. Please check whether your model has units roots, and you forgot to set diffuse_filter=1.' )
end
error_indicator.identification_moments=1;
2011-05-02 11:32:26 +02:00
end
ind_dMOMENTS = (find(max(abs(dMOMENTS'),[],1) > tol_deriv)); %index for non-zero rows
if isempty(ind_dMOMENTS) && any(any(isnan(dMOMENTS)))
error('There are NaN in the dMOMENTS matrix.')
error_indicator.identification_moments=1;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_spectrum
ind_dSPECTRUM = (find(max(abs(dSPECTRUM'),[],1) > tol_deriv)); %index for non-zero rows
if any(any(isnan(dSPECTRUM)))
warning_SPECTRUM = 'WARNING: There are NaN in the dSPECTRUM matrix. Note that identification based on spectrum does not support non-stationary models (yet).\n';
warning_SPECTRUM = [warning_SPECTRUM ' Skip identification analysis based on spectrum.\n'];
fprintf(warning_SPECTRUM);
%set indicator to neither display nor plot dSPECTRUM anymore
error_indicator.identification_spectrum = 1;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
end
if ~options_ident.no_identification_minimal
ind_dMINIMAL = (find(max(abs(dMINIMAL'),[],1) > tol_deriv)); %index for non-zero rows
if any(any(isnan(dMINIMAL)))
warning_MINIMAL = 'WARNING: There are NaN in the dMINIMAL matrix. Note that identification based on minimal system does not support non-stationary models (yet).\n';
warning_MINIMAL = [warning_MINIMAL ' Skip identification analysis based on minimal system.\n'];
fprintf(warning_MINIMAL);
%set indicator to neither display nor plot dMINIMAL anymore
error_indicator.identification_minimal = 1;
2011-05-02 11:32:26 +02:00
end
end
%The following cannot be reached yet due to erroring out when
%error_indicator.identification_moments is triggered
if error_indicator.identification_moments && error_indicator.identification_minimal && error_indicator.identification_spectrum
%display error if all three criteria fail
error(sprintf('identification_analyis: Stationarity condition(s) failed and/or diffuse_filter option missing.\nMake sure that for non-stationary models stationary transformations of non-stationary observables are used for checking identification.\n[TIP: use first differences].'));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% Check order conditions
if ~options_ident.no_identification_moments && ~error_indicator.identification_moments
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%check order condition of Iskrev (2010)
while length(ind_dMOMENTS) < totparam_nbr && nlags < 10
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%Try to add lags to autocovariogram if order condition fails
disp('The number of moments with non-zero derivative is smaller than the number of parameters')
disp(['Try increasing ar = ', int2str(nlags+1)])
nlags = nlags + 1;
options_ident_local=options_ident;
options_ident_local.no_identification_minimal = 1; %do not recompute dMINIMAL
options_ident_local.no_identification_spectrum = 1; %do not recompute dSPECTRUM
options_ident_local.ar = nlags; %store new lag number
options_.ar = nlags; %store new lag number
2023-12-18 07:48:27 +01:00
[~, ~, ~, ~, ~, ~, MOMENTS, dMOMENTS] = identification.get_jacobians(estim_params_, M_, options_, options_ident_local, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
ind_dMOMENTS = (find(max(abs(dMOMENTS'),[],1) > tol_deriv)); %new index with non-zero rows
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if length(ind_dMOMENTS) < totparam_nbr
warning_MOMENTS = 'WARNING: Order condition for dMOMENTS failed: There are not enough moments and too many parameters.\n';
warning_MOMENTS = [warning_MOMENTS ' The number of moments with non-zero derivative is smaller than the number of parameters up to 10 lags.\n'];
warning_MOMENTS = [warning_MOMENTS ' Either reduce the list of parameters, or further increase ar, or increase number of observables.\n'];
warning_MOMENTS = [warning_MOMENTS ' Skip identification analysis based on moments.\n'];
warning_MOMENTS = [warning_MOMENTS ' Skip identification strength analysis.\n'];
fprintf(warning_MOMENTS);
%set indicator to neither display nor plot dMOMENTS anymore
error_indicator.identification_moments = 1;
%options_ident.no_identification_moments = 1;
error_indicator.identification_strength = 1;
%options_ident.no_identification_strength = 1;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_minimal && ~error_indicator.identification_minimal
if length(ind_dMINIMAL) < size(dMINIMAL,2)
warning_MINIMAL = 'WARNING: Order condition for dMINIMAL failed: There are too many parameters or too few observable variables.\n';
warning_MINIMAL = [warning_MINIMAL ' The number of minimal system elements with non-zero derivative is smaller than the number of parameters.\n'];
warning_MINIMAL = [warning_MINIMAL ' Either reduce the list of parameters, or increase number of observables.\n'];
warning_MINIMAL = [warning_MINIMAL ' Skip identification analysis based on minimal state space system.\n'];
fprintf(warning_MINIMAL);
%set indicator to neither display nor plot dMINIMAL anymore
error_indicator.identification_minimal = 1;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
%Note that there is no order condition for dSPECTRUM, as the matrix is always of dimension totparam_nbr by totparam_nbr
if error_indicator.identification_moments && error_indicator.identification_minimal && error_indicator.identification_spectrum
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%error if all three criteria fail
error('identification_analyis: Order condition(s) failed');
end
if ~options_ident.no_identification_reducedform && ~error_indicator.identification_reducedform
ind_dREDUCEDFORM = (find(max(abs(dREDUCEDFORM'),[],1) > tol_deriv)); %index with non-zero rows
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
ind_dDYNAMIC = (find(max(abs(dDYNAMIC'),[],1) > tol_deriv)); %index with non-zero rows
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
DYNAMIC = DYNAMIC(ind_dDYNAMIC); %focus only on non-zero entries
si_dDYNAMIC = (dDYNAMIC(ind_dDYNAMIC,:)); %focus only on non-zero rows
if ~options_ident.no_identification_reducedform && ~error_indicator.identification_reducedform
REDUCEDFORM = REDUCEDFORM(ind_dREDUCEDFORM); %focus only on non-zero entries
si_dREDUCEDFORM = (dREDUCEDFORM(ind_dREDUCEDFORM,:)); %focus only on non-zero rows
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_moments && ~error_indicator.identification_moments
MOMENTS = MOMENTS(ind_dMOMENTS); %focus only on non-zero entries
si_dMOMENTS = (dMOMENTS(ind_dMOMENTS,:)); %focus only on non-zero derivatives
%% MOMENTS IDENTIFICATION STRENGTH ANALYSIS
if ~options_ident.no_identification_strength && ~error_indicator.identification_strength && init %only for initialization of persistent vars
ide_strength_dMOMENTS = NaN(1,totparam_nbr); %initialize
ide_strength_dMOMENTS_prior = NaN(1,totparam_nbr); %initialize
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
ide_uncert_unnormaliz = NaN(1,totparam_nbr); %initialize
if prior_exist
offset_prior = 0;
if ~isempty(estim_params_.var_exo) %stderr parameters come first
normaliz_prior_std = bayestopt_.p2(1:estim_params_.nvx)'; % normalize with prior standard deviation
offset_prior = offset_prior+estim_params_.nvx+estim_params_.nvn;
else
normaliz_prior_std=[]; %initialize
end
if ~isempty(estim_params_.corrx) %corr parameters come second
normaliz_prior_std = [normaliz_prior_std bayestopt_.p2(offset_prior+1:offset_prior+estim_params_.ncx)']; % normalize with prior standard deviation
offset_prior = offset_prior+estim_params_.ncx+estim_params_.ncn;
end
if ~isempty(estim_params_.param_vals) %model parameters come third
normaliz_prior_std = [normaliz_prior_std bayestopt_.p2(offset_prior+1:offset_prior+estim_params_.np)']; % normalize with prior standard deviation
end
2011-05-02 11:32:26 +02:00
else
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
normaliz_prior_std = NaN(1,totparam_nbr); %no prior information available, do not normalize
2011-05-02 11:32:26 +02:00
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
try
%try to compute asymptotic Hessian for identification strength analysis based on moments
if options_.order > 1
error('IDENTIFICATION STRENGTH: Analytic computation of Hessian is not available for ''order>1''. Identification strength is based on simulated moment uncertainty');
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% reset some options for faster computations
options_.irf = 0;
options_.noprint = 1;
options_.SpectralDensity.trigger = 0;
options_.periods = periods+100;
if options_.kalman_algo > 2
options_.kalman_algo = 1;
end
analytic_derivation = options_.analytic_derivation;
options_.analytic_derivation = -2; %this sets asy_Hess=1 in dsge_likelihood.m
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, options_.varobs);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
dataset_ = dseries(oo_.endo_simul(options_.varobs_id,100+1:end)',dates('1Q1'), options_.varobs); %get information on moments
derivatives_info.no_DLIK = 1;
bounds = prior_bounds(bayestopt_, options_.prior_trunc); %reset bounds as lb and ub must only be operational during mode-finding
%note that for order>1 we do not provide any information on DT,DYss,DOM in derivatives_info, such that dsge_likelihood creates an error. Therefore the computation will be based on simulated_moment_uncertainty for order>1.
2023-11-30 12:26:58 +01:00
[~, info, ~, ~, AHess, ~, ~, M_, options_, ~, oo_.dr] = dsge_likelihood(params', dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds, oo_.dr, oo_.steady_state,oo_.exo_steady_state, oo_.exo_det_steady_state. derivatives_info); %non-used output variables need to be set for octave for some reason
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%note that for the order of parameters in AHess we have: stderr parameters come first, corr parameters second, model parameters third. the order within these blocks corresponds to the order specified in the estimated_params block
options_.analytic_derivation = analytic_derivation; %reset option
AHess = -AHess; %take negative of hessian
if min(eig(AHess))<-tol_rank
error('identification.analysis: Analytic Hessian is not positive semi-definite!')
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
ide_hess.AHess = AHess; %store asymptotic Hessian
%normalize asymptotic hessian
deltaM = sqrt(diag(AHess));
iflag = any((deltaM.*deltaM)==0); %check if all second-order derivatives wrt to a single parameter are nonzero
tildaM = AHess./((deltaM)*(deltaM')); %this normalization is for numerical purposes
if iflag || rank(AHess)>rank(tildaM)
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(AHess, 0, tol_rank, tol_sv, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else %use normalized version if possible
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
indok = find(max(ide_hess.indno,[],1)==0);
ide_uncert_unnormaliz(indok) = sqrt(diag(inv(AHess(indok,indok))))';
ind1 = find(ide_hess.ind0);
cmm = si_dMOMENTS(:,ind1)*((AHess(ind1,ind1))\si_dMOMENTS(:,ind1)'); %covariance matrix of moments
temp1 = ((AHess(ind1,ind1))\si_dREDUCEDFORM(:,ind1)');
diag_chh = sum(si_dREDUCEDFORM(:,ind1)'.*temp1)';
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
ind1 = ind1(ind1>stderrparam_nbr+corrparam_nbr);
cdynamic = si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)*((AHess(ind1,ind1))\si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)');
flag_score = 1; %this is used for the title in identification.plot.m
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
catch
%Asymptotic Hessian via simulation
if options_.order > 1
% reset some options for faster computations
options_.irf = 0;
options_.noprint = 1;
options_.SpectralDensity.trigger = 0;
options_.periods = periods+100;
end
replic = max([replic, length(ind_dMOMENTS)*3]);
cmm = identification.simulated_moment_uncertainty(ind_dMOMENTS, periods, replic,options_,M_,oo_); %covariance matrix of moments
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
sd = sqrt(diag(cmm));
cc = cmm./(sd*sd');
[VV,DD,WW] = eig(cc);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
id = find(diag(DD)>tol_deriv);
siTMP = si_dMOMENTS./repmat(sd,[1 totparam_nbr]);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
MIM = (siTMP'*VV(:,id))*(DD(id,id)\(WW(:,id)'*siTMP));
clear siTMP;
ide_hess.AHess = MIM; %store asymptotic hessian
%normalize asymptotic hessian
deltaM = sqrt(diag(MIM));
iflag = any((deltaM.*deltaM)==0);
tildaM = MIM./((deltaM)*(deltaM'));
if iflag || rank(MIM)>rank(tildaM)
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(MIM, 0, tol_rank, tol_sv, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else %use normalized version if possible
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
indok = find(max(ide_hess.indno,[],1)==0);
ind1 = find(ide_hess.ind0);
temp1 = ((MIM(ind1,ind1))\si_dREDUCEDFORM(:,ind1)');
diag_chh = sum(si_dREDUCEDFORM(:,ind1)'.*temp1)';
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
ind1 = ind1(ind1>stderrparam_nbr+corrparam_nbr);
cdynamic = si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)*((MIM(ind1,ind1))\si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)');
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if ~isempty(indok)
ide_uncert_unnormaliz(indok) = (sqrt(diag(inv(tildaM(indok,indok))))./deltaM(indok))'; %sqrt(diag(inv(MIM(indok,indok))))';
end
flag_score = 0; %this is used for the title in identification.plot.m
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end % end of computing sample information matrix for identification strength measure
ide_strength_dMOMENTS(indok) = (1./(ide_uncert_unnormaliz(indok)'./abs(params(indok)'))); %this is s_i in Ratto and Iskrev (2011, p.13)
ide_strength_dMOMENTS_prior(indok) = (1./(ide_uncert_unnormaliz(indok)'./normaliz_prior_std(indok)')); %this is s_i^{prior} in Ratto and Iskrev (2011, p.14)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
sensitivity_zero_pos = find(isinf(deltaM));
deltaM_prior = deltaM.*abs(normaliz_prior_std'); %this is \Delta_i^{prior} in Ratto and Iskrev (2011, p.14)
deltaM = deltaM.*abs(params'); %this is \Delta_i in Ratto and Iskrev (2011, p.14)
quant = si_dMOMENTS./repmat(sqrt(diag(cmm)),1,totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if size(quant,1)==1
si_dMOMENTSnorm = abs(quant).*normaliz_prior_std;
else
si_dMOMENTSnorm = identification.vnorm(quant).*normaliz_prior_std;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
iy = find(diag_chh);
ind_dREDUCEDFORM = ind_dREDUCEDFORM(iy);
si_dREDUCEDFORM = si_dREDUCEDFORM(iy,:);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if ~isempty(iy)
quant = si_dREDUCEDFORM./repmat(sqrt(diag_chh(iy)),1,totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if size(quant,1)==1
si_dREDUCEDFORMnorm = abs(quant).*normaliz_prior_std;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
si_dREDUCEDFORMnorm = identification.vnorm(quant).*normaliz_prior_std;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
2011-05-02 11:32:26 +02:00
else
si_dREDUCEDFORMnorm = [];
2011-05-02 11:32:26 +02:00
end
diag_cdynamic = diag(cdynamic);
iy = find(diag_cdynamic);
ind_dDYNAMIC = ind_dDYNAMIC(iy);
si_dDYNAMIC = si_dDYNAMIC(iy,:);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if ~isempty(iy)
quant = si_dDYNAMIC./repmat(sqrt(diag_cdynamic(iy)),1,modparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if size(quant,1)==1
si_dDYNAMICnorm = abs(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
si_dDYNAMICnorm = identification.vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
else
si_dDYNAMICnorm=[];
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%store results of identification strength
ide_hess.ide_strength_dMOMENTS = ide_strength_dMOMENTS;
ide_hess.ide_strength_dMOMENTS_prior = ide_strength_dMOMENTS_prior;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
ide_hess.deltaM = deltaM;
ide_hess.deltaM_prior = deltaM_prior;
ide_hess.sensitivity_zero_pos = sensitivity_zero_pos;
ide_hess.identified_parameter_indices = indok;
ide_hess.flag_score = flag_score;
ide_dynamic.si_dDYNAMICnorm = si_dDYNAMICnorm;
ide_moments.si_dMOMENTSnorm = si_dMOMENTSnorm;
ide_reducedform.si_dREDUCEDFORMnorm = si_dREDUCEDFORMnorm;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end %end of identification strength analysis
end
%% Normalization of Jacobians
% For Dynamic, ReducedForm, Moment and Minimal Jacobian: rescale each row by its largest element in absolute value
% For Spectrum: transform into correlation-type matrices (as above with AHess)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if normalize_jacobians
norm_dDYNAMIC = max(abs(si_dDYNAMIC),[],2);
norm_dDYNAMIC = norm_dDYNAMIC(:,ones(size(dDYNAMIC,2),1));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
norm_dDYNAMIC = 1;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
% store into structure (not everything is used later on)
ide_dynamic.ind_dDYNAMIC = ind_dDYNAMIC;
ide_dynamic.norm_dDYNAMIC = norm_dDYNAMIC;
ide_dynamic.si_dDYNAMIC = si_dDYNAMIC;
ide_dynamic.dDYNAMIC = dDYNAMIC;
ide_dynamic.DYNAMIC = DYNAMIC;
if ~options_ident.no_identification_reducedform && ~error_indicator.identification_reducedform
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if normalize_jacobians
norm_dREDUCEDFORM = max(abs(si_dREDUCEDFORM),[],2);
norm_dREDUCEDFORM = norm_dREDUCEDFORM(:,ones(totparam_nbr,1));
else
norm_dREDUCEDFORM = 1;
end
% store into structure (not everything is used later on)
ide_reducedform.ind_dREDUCEDFORM = ind_dREDUCEDFORM;
ide_reducedform.norm_dREDUCEDFORM = norm_dREDUCEDFORM;
ide_reducedform.si_dREDUCEDFORM = si_dREDUCEDFORM;
ide_reducedform.dREDUCEDFORM = dREDUCEDFORM;
ide_reducedform.REDUCEDFORM = REDUCEDFORM;
end
if ~options_ident.no_identification_moments && ~error_indicator.identification_moments
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if normalize_jacobians
norm_dMOMENTS = max(abs(si_dMOMENTS),[],2);
norm_dMOMENTS = norm_dMOMENTS(:,ones(totparam_nbr,1));
else
norm_dMOMENTS = 1;
end
% store into structure (not everything is used later on)
ide_moments.ind_dMOMENTS = ind_dMOMENTS;
ide_moments.norm_dMOMENTS = norm_dMOMENTS;
ide_moments.si_dMOMENTS = si_dMOMENTS;
ide_moments.dMOMENTS = dMOMENTS;
ide_moments.MOMENTS = MOMENTS;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if advanced
% here we do not normalize (i.e. we set norm_dMOMENTS=1) as the OLS in identification.bruteforce is very sensitive to norm_dMOMENTS
[ide_moments.pars, ide_moments.cosndMOMENTS] = identification.bruteforce(M_.dname,M_.fname,dMOMENTS(ind_dMOMENTS,:), max_dim_cova_group, options_.TeX, options_ident.name_tex, options_ident.tittxt, tol_deriv);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
%here we focus on the unnormalized S and V, which is then used in identification.plot.m and for prior_mc > 1
[~, S, V] = svd(dMOMENTS(ind_dMOMENTS,:),0);
if size(S,1) == 1
S = S(1); % edge case that S is not a matrix but a row vector
else
S = diag(S);
end
S = [S;zeros(size(dMOMENTS,2)-length(ind_dMOMENTS),1)];
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if totparam_nbr > 8
ide_moments.S = S([1:4, end-3:end]);
ide_moments.V = V(:,[1:4, end-3:end]);
else
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
ide_moments.S = S;
ide_moments.V = V;
end
2017-05-16 12:42:01 +02:00
end
if ~options_ident.no_identification_minimal && ~error_indicator.identification_minimal
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if normalize_jacobians
ind_dMINIMAL = (find(max(abs(dMINIMAL'),[],1) > tol_deriv)); %index for non-zero rows
norm_dMINIMAL = max(abs(dMINIMAL(ind_dMINIMAL,:)),[],2);
norm_dMINIMAL = norm_dMINIMAL(:,ones(size(dMINIMAL,2),1));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
norm_dMINIMAL = 1;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
% store into structure (not everything is used later on)
ide_minimal.ind_dMINIMAL = ind_dMINIMAL;
ide_minimal.norm_dMINIMAL = norm_dMINIMAL;
ide_minimal.dMINIMAL = dMINIMAL;
end
if ~options_ident.no_identification_spectrum && ~error_indicator.identification_spectrum
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if normalize_jacobians
ind_dSPECTRUM = (find(max(abs(dSPECTRUM'),[],1) > tol_deriv)); %index for non-zero rows
tilda_dSPECTRUM = zeros(size(dSPECTRUM));
delta_dSPECTRUM = sqrt(diag(dSPECTRUM(ind_dSPECTRUM,ind_dSPECTRUM)));
tilda_dSPECTRUM(ind_dSPECTRUM,ind_dSPECTRUM) = dSPECTRUM(ind_dSPECTRUM,ind_dSPECTRUM)./((delta_dSPECTRUM)*(delta_dSPECTRUM'));
norm_dSPECTRUM = max(abs(dSPECTRUM(ind_dSPECTRUM,:)),[],2);
norm_dSPECTRUM = norm_dSPECTRUM(:,ones(size(dSPECTRUM,2),1));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
tilda_dSPECTRUM = dSPECTRUM;
norm_dSPECTRUM = 1;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
% store into structure (not everything is used later on)
ide_spectrum.ind_dSPECTRUM = ind_dSPECTRUM;
ide_spectrum.norm_dSPECTRUM = norm_dSPECTRUM;
ide_spectrum.tilda_dSPECTRUM = tilda_dSPECTRUM;
ide_spectrum.dSPECTRUM = dSPECTRUM;
ide_spectrum.dSPECTRUM_NO_MEAN = dSPECTRUM_NO_MEAN;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%% Perform identification checks, i.e. find out which parameters are involved
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if checks_via_subsets
% identification.checks_via_subsets is only for debugging
[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = ...
identification.checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident, error_indicator);
if ~error_indicator.identification_minimal
ide_minimal.minimal_state_space=1;
else
ide_minimal.minimal_state_space=0;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
[ide_dynamic.cond, ide_dynamic.rank, ide_dynamic.ind0, ide_dynamic.indno, ide_dynamic.ino, ide_dynamic.Mco, ide_dynamic.Pco, ide_dynamic.jweak, ide_dynamic.jweak_pair] = ...
identification.checks(dDYNAMIC(ind_dDYNAMIC,:)./norm_dDYNAMIC, 1, tol_rank, tol_sv, modparam_nbr);
if ~options_ident.no_identification_reducedform && ~error_indicator.identification_reducedform
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
[ide_reducedform.cond, ide_reducedform.rank, ide_reducedform.ind0, ide_reducedform.indno, ide_reducedform.ino, ide_reducedform.Mco, ide_reducedform.Pco, ide_reducedform.jweak, ide_reducedform.jweak_pair] = ...
identification.checks(dREDUCEDFORM(ind_dREDUCEDFORM,:)./norm_dREDUCEDFORM, 1, tol_rank, tol_sv, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_moments && ~error_indicator.identification_moments
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
[ide_moments.cond, ide_moments.rank, ide_moments.ind0, ide_moments.indno, ide_moments.ino, ide_moments.Mco, ide_moments.Pco, ide_moments.jweak, ide_moments.jweak_pair] = ...
identification.checks(dMOMENTS(ind_dMOMENTS,:)./norm_dMOMENTS, 1, tol_rank, tol_sv, totparam_nbr);
end
if ~options_ident.no_identification_minimal
if ~error_indicator.identification_minimal
[ide_minimal.cond, ide_minimal.rank, ide_minimal.ind0, ide_minimal.indno, ide_minimal.ino, ide_minimal.Mco, ide_minimal.Pco, ide_minimal.jweak, ide_minimal.jweak_pair] = ...
identification.checks(dMINIMAL(ind_dMINIMAL,:)./norm_dMINIMAL, 2, tol_rank, tol_sv, totparam_nbr);
ide_minimal.minimal_state_space=1;
else
ide_minimal.minimal_state_space=0;
end
end
if ~options_ident.no_identification_spectrum && ~error_indicator.identification_spectrum
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
[ide_spectrum.cond, ide_spectrum.rank, ide_spectrum.ind0, ide_spectrum.indno, ide_spectrum.ino, ide_spectrum.Mco, ide_spectrum.Pco, ide_spectrum.jweak, ide_spectrum.jweak_pair] = ...
identification.checks(tilda_dSPECTRUM, 3, tol_rank, tol_sv, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
end
end