dynare/matlab/identification_checks_via_s...

510 lines
26 KiB
Matlab
Raw Normal View History

function [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)
%[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)
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
% -------------------------------------------------------------------------
% Finds problematic sets of paramters via checking the necessary rank condition
% of the Jacobians for all possible combinations of parameters. The rank is
% computed via an inbuild function based on the SVD, similar to matlab's
% rank. The idea is that once we have the Jacobian for all parameters, we
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
% can easily set up Jacobians containing all combinations of parameters by
% picking the relevant columns/elements of the full Jacobian. Then the rank
% of these smaller Jacobians indicates whether this paramter combination is
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
% identified or not. To speed up computations:
% (1) single parameters are removed from possible higher-order sets,
% (2) for parameters that are collinear, i.e. rank failure for 2 element sets,
% we replace the second parameter by the first one, and then compute
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
% higher-order combinations [uncommented]
% (3) all lower-order problematic sets are removed from higher-order sets
% by an inbuild function
% (4) we could replace nchoosek by a mex version, e.g. VChooseK
% (https://de.mathworks.com/matlabcentral/fileexchange/26190-vchoosek) as
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
% nchoosek could be the bottleneck in terms of speed (and memory for models
% with totparam_nbr > 150)
% =========================================================================
% INPUTS
% ide_reducedform: [structure] Containing results from identification
% analysis based on the reduced-form solution (Ratto
% and Iskrev, 2011). If either options_ident.no_identification_reducedform
% or error_indicator.identification_reducedform are 1 then the search for problematic parameter sets will be skipped
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] Containing results from identification
% analysis based on moments (Iskrev, 2010). If either
% options_ident.no_identification_moments or error_indicator.identification_moments are 1 then the search for
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
% problematic parameter sets will be skipped
% ide_spectrum: [structure] Containing results from identification
% analysis based on the spectrum (Qu and Tkachenko, 2012).
% If either options_ident.no_identification_spectrum or error_indicator.identification_spectrum are 1 then the search for
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
% problematic parameter sets will be skipped
% ide_minimal: [structure] Containing results from identification
% analysis based on the minimal state space system
% (Komunjer and Ng, 2011). If either options_ident.no_identification_minimal or
% error_indicator.identification_minimal are 1 then the search for problematic parameter sets will be skipped
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: [integer] number of estimated stderr, corr and model parameters
% numzerotolrank: [double] tolerance level for rank compuations
% error_indicator [structure] indicators whether objects could be computed
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
% -------------------------------------------------------------------------
% OUTPUTS
% ide_reducedform, ide_moments, ide_spectrum, ide_minimal are augmented by the
% following fields:
% * problpars: [1 by totparam_nbr] cell with the following structure for j=1:totparam_nbr
% problpars{j}: [nonidentified_j_set_parameters_nbr by j]
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
% matrix with j collinear parameters in each row
% * rank: [integer] rank of Jacobian
% -------------------------------------------------------------------------
% This function is called by
% * identification_analysis.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
% =========================================================================
% Copyright © 2019-2021 Dynare Team
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 file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <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
% =========================================================================
%% initialize output objects and get options
no_identification_dynamic = 0; %always compute dynamic
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
no_identification_reducedform = options_ident.no_identification_reducedform;
no_identification_moments = options_ident.no_identification_moments;
no_identification_spectrum = options_ident.no_identification_spectrum;
no_identification_minimal = options_ident.no_identification_minimal;
tol_rank = options_ident.tol_rank;
max_dim_subsets_groups = options_ident.max_dim_subsets_groups;
dynamic_problpars = cell(1,max_dim_subsets_groups);
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
reducedform_problpars = cell(1,max_dim_subsets_groups);
moments_problpars = cell(1,max_dim_subsets_groups);
spectrum_problpars = cell(1,max_dim_subsets_groups);
minimal_problpars = cell(1,max_dim_subsets_groups);
indtotparam = 1:totparam_nbr; %initialize index of parameters
%% Prepare Jacobians and check rank
% initialize linear rational expectations model
if ~no_identification_dynamic
dDYNAMIC = ide_dynamic.dDYNAMIC;
dDYNAMIC(ide_dynamic.ind_dDYNAMIC,:) = dDYNAMIC(ide_dynamic.ind_dDYNAMIC,:)./ide_dynamic.norm_dDYNAMIC; %normalize
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 > modparam_nbr
dDYNAMIC = [zeros(size(ide_dynamic.dDYNAMIC,1),totparam_nbr-modparam_nbr) dDYNAMIC]; %add derivatives wrt stderr and corr parameters
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 strcmp(tol_rank,'robust')
rank_dDYNAMIC = rank(full(dDYNAMIC)); %compute rank with imposed tolerance level
else
rank_dDYNAMIC = rank(full(dDYNAMIC),tol_rank); %compute rank with imposed tolerance level
end
ide_dynamic.rank = rank_dDYNAMIC;
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 rank criteria for full Jacobian
if rank_dDYNAMIC == 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
% all parameters are identifiable
no_identification_dynamic = 1; %skip in the following
indparam_dDYNAMIC = [];
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
% there is lack of identification
indparam_dDYNAMIC = indtotparam; %initialize for nchoosek
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
indparam_dDYNAMIC = []; %empty for nchoosek
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
% initialize for reduced form solution criteria
if ~no_identification_reducedform && ~error_indicator.identification_reducedform
dREDUCEDFORM = ide_reducedform.dREDUCEDFORM;
dREDUCEDFORM(ide_reducedform.ind_dREDUCEDFORM,:) = dREDUCEDFORM(ide_reducedform.ind_dREDUCEDFORM,:)./ide_reducedform.norm_dREDUCEDFORM; %normalize
if strcmp(tol_rank,'robust')
rank_dREDUCEDFORM = rank(full(dREDUCEDFORM)); %compute rank with imposed tolerance level
else
rank_dREDUCEDFORM = rank(full(dREDUCEDFORM),tol_rank); %compute rank with imposed tolerance level
end
ide_reducedform.rank = rank_dREDUCEDFORM;
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 rank criteria for full Jacobian
if rank_dREDUCEDFORM == 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
% all parameters are identifiable
no_identification_reducedform = 1; %skip in the following
indparam_dREDUCEDFORM = [];
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
% there is lack of identification
indparam_dREDUCEDFORM = indtotparam; %initialize for nchoosek
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
indparam_dREDUCEDFORM = []; %empty for nchoosek
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
% initialize for moments criteria
if ~no_identification_moments && ~error_indicator.identification_moments
dMOMENTS = ide_moments.dMOMENTS;
dMOMENTS(ide_moments.ind_dMOMENTS,:) = dMOMENTS(ide_moments.ind_dMOMENTS,:)./ide_moments.norm_dMOMENTS; %normalize
if strcmp(tol_rank,'robust')
rank_dMOMENTS = rank(full(dMOMENTS)); %compute rank with imposed tolerance level
else
rank_dMOMENTS = rank(full(dMOMENTS),tol_rank); %compute rank with imposed tolerance level
end
ide_moments.rank = rank_dMOMENTS;
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 rank criteria for full Jacobian
if rank_dMOMENTS == 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
% all parameters are identifiable
no_identification_moments = 1; %skip in the following
indparam_dMOMENTS = [];
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
% there is lack of identification
indparam_dMOMENTS = indtotparam; %initialize for nchoosek
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
indparam_dMOMENTS = []; %empty for nchoosek
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
% initialize for spectrum criteria
if ~no_identification_spectrum && ~error_indicator.identification_spectrum
dSPECTRUM = ide_spectrum.tilda_dSPECTRUM; %tilda dSPECTRUM is normalized dSPECTRUM matrix in identification_analysis.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
%alternative normalization
%dSPECTRUM = ide_spectrum.dSPECTRUM;
%dSPECTRUM(ide_spectrum.ind_dSPECTRUM,:) = dSPECTRUM(ide_spectrum.ind_dSPECTRUM,:)./ide_spectrum.norm_dSPECTRUM; %normalize
if strcmp(tol_rank,'robust')
rank_dSPECTRUM = rank(full(dSPECTRUM)); %compute rank with imposed tolerance level
else
rank_dSPECTRUM = rank(full(dSPECTRUM),tol_rank); %compute rank with imposed tolerance level
end
ide_spectrum.rank = rank_dSPECTRUM;
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 rank criteria for full Jacobian
if rank_dSPECTRUM == 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
% all parameters are identifiable
no_identification_spectrum = 1; %skip in the following
indparam_dSPECTRUM = [];
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
% lack of identification
indparam_dSPECTRUM = indtotparam; %initialize for nchoosek
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
indparam_dSPECTRUM = []; %empty for nchoosek
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
% initialize for minimal system criteria
if ~no_identification_minimal && ~error_indicator.identification_minimal
dMINIMAL = ide_minimal.dMINIMAL;
dMINIMAL(ide_minimal.ind_dMINIMAL,:) = dMINIMAL(ide_minimal.ind_dMINIMAL,:)./ide_minimal.norm_dMINIMAL; %normalize
dMINIMAL_par = dMINIMAL(:,1:totparam_nbr); %part of dMINIMAL that is dependent on parameters
dMINIMAL_rest = dMINIMAL(:,(totparam_nbr+1):end); %part of dMINIMAL that is independent of parameters
if strcmp(tol_rank,'robust')
rank_dMINIMAL = rank(full(dMINIMAL)); %compute rank via SVD see function below
else
rank_dMINIMAL = rank(full(dMINIMAL),tol_rank); %compute rank via SVD see function below
end
ide_minimal.rank = rank_dMINIMAL;
dMINIMAL_fixed_rank_nbr = size(dMINIMAL_rest,2);
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 rank criteria for full Jacobian
if rank_dMINIMAL == totparam_nbr + dMINIMAL_fixed_rank_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
% all parameters are identifiable
no_identification_minimal = 1; %skip in the following
indparam_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
else
% lack of identification
indparam_dMINIMAL = indtotparam; %initialize for nchoosek
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
indparam_dMINIMAL = []; %empty for nchoosek
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
%% Check single parameters
for j=1:totparam_nbr
if ~no_identification_dynamic
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
% Columns correspond to single parameters, i.e. full rank would be equal to 1
if strcmp(tol_rank,'robust')
if rank(full(dDYNAMIC(:,j))) == 0
dynamic_problpars{1} = [dynamic_problpars{1};j];
end
else
if rank(full(dDYNAMIC(:,j)),tol_rank) == 0
dynamic_problpars{1} = [dynamic_problpars{1};j];
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
end
if ~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
% Columns correspond to single parameters, i.e. full rank would be equal to 1
if strcmp(tol_rank,'robust')
if rank(full(dREDUCEDFORM(:,j))) == 0
reducedform_problpars{1} = [reducedform_problpars{1};j];
end
else
if rank(full(dREDUCEDFORM(:,j)),tol_rank) == 0
reducedform_problpars{1} = [reducedform_problpars{1};j];
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
end
if ~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
% Columns correspond to single parameters, i.e. full rank would be equal to 1
if strcmp(tol_rank,'robust')
if rank(full(dMOMENTS(:,j))) == 0
moments_problpars{1} = [moments_problpars{1};j];
end
else
if rank(full(dMOMENTS(:,j)),tol_rank) == 0
moments_problpars{1} = [moments_problpars{1};j];
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
end
if ~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
% Diagonal values correspond to single parameters, absolute value needs to be greater than tolerance level
if abs(dSPECTRUM(j,j)) < tol_rank
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
spectrum_problpars{1} = [spectrum_problpars{1};j];
end
end
if ~no_identification_minimal && ~error_indicator.identification_minimal
% Columns of dMINIMAL_par correspond to single parameters, needs to be augmented with dMINIMAL_rest (part that is independent of parameters),
% full rank would be equal to 1+dMINIMAL_fixed_rank_nbr
if strcmp(tol_rank,'robust')
if rank(full([dMINIMAL_par(:,j) dMINIMAL_rest])) == dMINIMAL_fixed_rank_nbr
minimal_problpars{1} = [minimal_problpars{1};j];
end
else
if rank(full([dMINIMAL_par(:,j) dMINIMAL_rest]),tol_rank) == dMINIMAL_fixed_rank_nbr
minimal_problpars{1} = [minimal_problpars{1};j];
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
end
end
% Check whether lack of identification is only due to single parameters
if ~no_identification_dynamic
if size(dynamic_problpars{1},1) == (totparam_nbr - rank_dDYNAMIC)
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
%found all nonidentified parameter sets
no_identification_dynamic = 1; %skip in the following
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
%still parameter sets that are nonidentified
indparam_dDYNAMIC(dynamic_problpars{1}) = []; %remove single unidentified parameters from higher-order sets of indparam
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 ~no_identification_reducedform && ~error_indicator.identification_reducedform
if size(reducedform_problpars{1},1) == (totparam_nbr - rank_dREDUCEDFORM)
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
%found all nonidentified parameter sets
no_identification_reducedform = 1; %skip in the following
else
%still parameter sets that are nonidentified
indparam_dREDUCEDFORM(reducedform_problpars{1}) = []; %remove single unidentified parameters from higher-order sets of indparam
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 ~no_identification_moments && ~error_indicator.identification_moments
if size(moments_problpars{1},1) == (totparam_nbr - rank_dMOMENTS)
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
%found all nonidentified parameter sets
no_identification_moments = 1; %skip in the following
else
%still parameter sets that are nonidentified
indparam_dMOMENTS(moments_problpars{1}) = []; %remove single unidentified parameters from higher-order sets of indparam
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 ~no_identification_spectrum && ~error_indicator.identification_spectrum
if size(spectrum_problpars{1},1) == (totparam_nbr - rank_dSPECTRUM)
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
%found all nonidentified parameter sets
no_identification_spectrum = 1; %skip in the following
else
%still parameter sets that are nonidentified
indparam_dSPECTRUM(spectrum_problpars{1}) = []; %remove single unidentified parameters from higher-order sets of indparam
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 ~no_identification_minimal && ~error_indicator.identification_minimal
if size(minimal_problpars{1},1) == (totparam_nbr + dMINIMAL_fixed_rank_nbr - rank_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
%found all nonidentified parameter sets
no_identification_minimal = 1; %skip in the following
else
%still parameter sets that are nonidentified
indparam_dMINIMAL(minimal_problpars{1}) = []; %remove single unidentified parameters from higher-order sets of indparam
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
%% check higher order (j>1) parameter sets
%get common parameter indices from which to sample higher-order sets using nchoosek (we do not want to run nchoosek three times), most of the times indparamdMOMENTS, indparamdSPECTRUM, and indparamdMINIMAL are equal anyways
indtotparam = unique([indparam_dDYNAMIC indparam_dREDUCEDFORM indparam_dMOMENTS indparam_dSPECTRUM indparam_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
for j=2:min(length(indtotparam),max_dim_subsets_groups) % Check j-element subsets
h = dyn_waitbar(0,['Brute force collinearity for ' int2str(j) ' parameters.']);
%Step1: get all possible unique subsets of j elements
if ~no_identification_dynamic ...
|| (~no_identification_reducedform && ~error_indicator.identification_reducedform)...
|| (~no_identification_moments && ~error_indicator.identification_moments)...
|| (~no_identification_spectrum && ~error_indicator.identification_spectrum)...
|| (~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
indexj=nchoosek(int16(indtotparam),j); % int16 speeds up nchoosek
% One could also use a mex version of nchoosek to speed this up, e.g.VChooseK from https://de.mathworks.com/matlabcentral/fileexchange/26190-vchoosek
end
%Step 2: remove already problematic sets and initialize rank vector
if ~no_identification_dynamic
indexj_dDYNAMIC = RemoveProblematicParameterSets(indexj,dynamic_problpars);
rankj_dDYNAMIC = zeros(size(indexj_dDYNAMIC,1),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
indexj_dDYNAMIC = [];
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 ~no_identification_reducedform && ~error_indicator.identification_reducedform
indexj_dREDUCEDFORM = RemoveProblematicParameterSets(indexj,reducedform_problpars);
rankj_dREDUCEDFORM = zeros(size(indexj_dREDUCEDFORM,1),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
indexj_dREDUCEDFORM = [];
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 ~no_identification_moments && ~error_indicator.identification_moments
indexj_dMOMENTS = RemoveProblematicParameterSets(indexj,moments_problpars);
rankj_dMOMENTS = zeros(size(indexj_dMOMENTS,1),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
indexj_dMOMENTS = [];
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 ~no_identification_spectrum && ~error_indicator.identification_spectrum
indexj_dSPECTRUM = RemoveProblematicParameterSets(indexj,spectrum_problpars);
rankj_dSPECTRUM = zeros(size(indexj_dSPECTRUM,1),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
indexj_dSPECTRUM = [];
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 ~no_identification_minimal && ~error_indicator.identification_minimal
indexj_dMINIMAL = RemoveProblematicParameterSets(indexj,minimal_problpars);
rankj_dMINIMAL = zeros(size(indexj_dMINIMAL,1),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
indexj_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
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
%Step3: Check rank criteria on submatrices
k_dDYNAMIC=0; k_dREDUCEDFORM=0; k_dMOMENTS=0; k_dSPECTRUM=0; k_dMINIMAL=0; %initialize counters
maxk = max([size(indexj_dDYNAMIC,1), size(indexj_dREDUCEDFORM,1), size(indexj_dMOMENTS,1), size(indexj_dMINIMAL,1), size(indexj_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
for k=1:maxk
if ~no_identification_dynamic
k_dDYNAMIC = k_dDYNAMIC+1;
if k_dDYNAMIC <= size(indexj_dDYNAMIC,1)
dDYNAMIC_j = dDYNAMIC(:,indexj_dDYNAMIC(k_dDYNAMIC,:)); % pick columns that correspond to parameter subset
if strcmp(tol_rank,'robust')
rankj_dDYNAMIC(k_dDYNAMIC,1) = rank(full(dDYNAMIC_j)); %compute rank with imposed tolerance
else
rankj_dDYNAMIC(k_dDYNAMIC,1) = rank(full(dDYNAMIC_j),tol_rank); %compute rank with imposed tolerance
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
end
if ~no_identification_reducedform && ~error_indicator.identification_reducedform
k_dREDUCEDFORM = k_dREDUCEDFORM+1;
if k_dREDUCEDFORM <= size(indexj_dREDUCEDFORM,1)
dREDUCEDFORM_j = dREDUCEDFORM(:,indexj_dREDUCEDFORM(k_dREDUCEDFORM,:)); % pick columns that correspond to parameter subset
if strcmp(tol_rank,'robust')
rankj_dREDUCEDFORM(k_dREDUCEDFORM,1) = rank(full(dREDUCEDFORM_j)); %compute rank with imposed tolerance
else
rankj_dREDUCEDFORM(k_dREDUCEDFORM,1) = rank(full(dREDUCEDFORM_j),tol_rank); %compute rank with imposed tolerance
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
end
if ~no_identification_moments && ~error_indicator.identification_moments
k_dMOMENTS = k_dMOMENTS+1;
if k_dMOMENTS <= size(indexj_dMOMENTS,1)
dMOMENTS_j = dMOMENTS(:,indexj_dMOMENTS(k_dMOMENTS,:)); % pick columns that correspond to parameter subset
if strcmp(tol_rank,'robust')
rankj_dMOMENTS(k_dMOMENTS,1) = rank(full(dMOMENTS_j)); %compute rank with imposed tolerance
else
rankj_dMOMENTS(k_dMOMENTS,1) = rank(full(dMOMENTS_j),tol_rank); %compute rank with imposed tolerance
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
end
if ~no_identification_minimal && ~error_indicator.identification_minimal
k_dMINIMAL = k_dMINIMAL+1;
if k_dMINIMAL <= size(indexj_dMINIMAL,1)
dMINIMAL_j = [dMINIMAL_par(:,indexj_dMINIMAL(k_dMINIMAL,:)) dMINIMAL_rest]; % pick columns in dMINIMAL_par that correspond to parameter subset and augment with parameter-indepdendet part dMINIMAL_rest
if strcmp(tol_rank,'robust')
rankj_dMINIMAL(k_dMINIMAL,1) = rank(full(dMINIMAL_j)); %compute rank with imposed tolerance
else
rankj_dMINIMAL(k_dMINIMAL,1) = rank(full(dMINIMAL_j),tol_rank); %compute rank with imposed tolerance
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
end
if ~no_identification_spectrum && ~error_indicator.identification_spectrum
k_dSPECTRUM = k_dSPECTRUM+1;
if k_dSPECTRUM <= size(indexj_dSPECTRUM,1)
dSPECTRUM_j = dSPECTRUM(indexj_dSPECTRUM(k_dSPECTRUM,:),indexj_dSPECTRUM(k_dSPECTRUM,:)); % pick rows and columns that correspond to parameter subset
if strcmp(tol_rank,'robust')
rankj_dSPECTRUM(k_dSPECTRUM,1) = rank(full(dSPECTRUM_j)); % Compute rank with imposed tol
else
rankj_dSPECTRUM(k_dSPECTRUM,1) = rank(full(dSPECTRUM_j),tol_rank); % Compute rank with imposed tol
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
end
dyn_waitbar(k/maxk,h)
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
%Step 4: Compare rank conditions for all possible subsets. If rank condition is violated, then the corresponding numbers of the parameters are stored
if ~no_identification_dynamic
dynamic_problpars{j} = indexj_dDYNAMIC(rankj_dDYNAMIC < j,:);
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 ~no_identification_reducedform && ~error_indicator.identification_reducedform
reducedform_problpars{j} = indexj_dREDUCEDFORM(rankj_dREDUCEDFORM < j,:);
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 ~no_identification_moments && ~error_indicator.identification_moments
moments_problpars{j} = indexj_dMOMENTS(rankj_dMOMENTS < j,:);
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 ~no_identification_minimal && ~error_indicator.identification_minimal
minimal_problpars{j} = indexj_dMINIMAL(rankj_dMINIMAL < (j+dMINIMAL_fixed_rank_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 ~no_identification_spectrum && ~error_indicator.identification_spectrum
spectrum_problpars{j} = indexj_dSPECTRUM(rankj_dSPECTRUM < j,:);
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
% % Optional Step 5: % remove redundant 2-sets, eg. if the problematic sets are [(p1,p2);(p1,p3);(p2,p3)], then the unique problematic parameter sets are actually only [(p1,p2),(p1,p3)]
% if j == 2
% for jj=1:max([size(dynamic_problpars{2},1), size(reducedform_problpars{2},1), size(moments_problpars{2},1), size(spectrum_problpars{2},1), size(minimal_problpars{2},1)])
% if jj <= size(dynamic_problpars{2},1)
% dynamic_problpars{2}(dynamic_problpars{2}(jj,2)==dynamic_problpars{2}(:,1)) = dynamic_problpars{2}(jj,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
% if jj <= size(reducedform_problpars{2},1)
% reducedform_problpars{2}(reducedform_problpars{2}(jj,2)==reducedform_problpars{2}(:,1)) = reducedform_problpars{2}(jj,1);
% end
% if jj <= size(moments_problpars{2},1)
% moments_problpars{2}(moments_problpars{2}(jj,2)==moments_problpars{2}(:,1)) = moments_problpars{2}(jj,1);
% end
% if jj <= size(spectrum_problpars{2},1)
% spectrum_problpars{2}(spectrum_problpars{2}(jj,2)==spectrum_problpars{2}(:,1)) = spectrum_problpars{2}(jj,1);
% end
% if jj <= size(minimal_problpars{2},1)
% minimal_problpars{2}(minimal_problpars{2}(jj,2)==minimal_problpars{2}(:,1)) = minimal_problpars{2}(jj,1);
% end
% end
% dynamic_problpars{2} = unique(dynamic_problpars{2},'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
% reducedform_problpars{2} = unique(reducedform_problpars{2},'rows');
% moments_problpars{2} = unique(moments_problpars{2},'rows');
% spectrum_problpars{2} = unique(spectrum_problpars{2},'rows');
% minimal_problpars{2} = unique(minimal_problpars{2},'rows');
% % in indparam we replace the second parameter of problematic 2-sets by the observational equivalent first parameter to speed up nchoosek
% idx2 = unique([dynamic_problpars{2}; reducedform_problpars{2}; moments_problpars{2}; spectrum_problpars{2}; minimal_problpars{2}],'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
% if ~isempty(idx2)
% indtotparam(ismember(indtotparam,idx2(:,2))) = [];
% end
% end
dyn_waitbar_close(h);
end
%% Save output variables
if ~isempty(dynamic_problpars{1})
dynamic_problpars{1}(ismember(dynamic_problpars{1},1:(totparam_nbr-modparam_nbr))) = []; % get rid of stderr and corr variables for dynamic
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_dynamic.problpars = dynamic_problpars;
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.problpars = reducedform_problpars;
ide_moments.problpars = moments_problpars;
ide_spectrum.problpars = spectrum_problpars;
ide_minimal.problpars = minimal_problpars;
%% Auxiliary functions
function idx = RemoveProblematicParameterSets(idx,problparset)
% Remove already problematic parameters
% INPUTS:
% * idx: complete index of possible combinations
% * problparset [cell] of all lower order combinations that are problematic
% * iset [integer] number of elements in set to consider
% OUTPUTS:
% * idx: index of possible combinations without already
% problematic lower order sets
iset = size(idx,2);
for iii=1:(iset-1)
if ~isempty(problparset{iii})
for kkk=1:size(problparset{iii},1)
idx((sum(ismember(idx,problparset{iii}(kkk,:)),2)==iii),:) = [];
end
end
end
end%RemoveProblematicParameterSets ed
end %main function end