dynare/matlab/+identification/run.m

982 lines
59 KiB
Matlab
Raw Permalink Normal View History

function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = run(M_,oo_,options_,bayestopt_,estim_params_,options_ident, pdraws0)
% [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = run(options_ident, pdraws0)
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
% -------------------------------------------------------------------------
2020-01-16 14:43:39 +01:00
% This function is called, when the user specifies identification(...); in the mod file. It prepares all identification analysis:
% (1) set options, local and persistent variables for a new identification
% analysis either for a single point or a MC Sample. It also displays and plots the results
% (2) load, display and plot a previously saved identification analysis
2020-01-16 14:43:39 +01:00
%
% Note 1: This function does not output the arguments to the workspace, but saves results to the folder identification
% Note 2: If you want to use this function directly in the mod file and workspace, you still have
% to put identification in your mod file, otherwise the preprocessor won't provide all necessary objects
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
% =========================================================================
% INPUTS
2023-11-30 12:26:58 +01:00
% * M_ [structure] Matlab's structure describing the model
% * oo_ [structure] Matlab's structure describing the results
% * options_ [structure] Matlab's structure describing the current options
% * bayestopt_ [structure] describing the priors
% * estim_params_ [structure] characterizing parameters to be estimated
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * options_ident [structure] identification options
% * pdraws0 [SampleSize by totparam_nbr] optional: matrix of MC sample of model parameters
% -------------------------------------------------------------------------
% OUTPUTS
% * pdraws [matrix] MC sample of model params used
% * STO_REDUCEDFORM, [matrix] MC sample of entries in steady state and reduced form model solution (stacked vertically)
% * STO_MOMENTS, [matrix] MC sample of entries in theoretical first two moments (stacked vertically)
% * STO_DYNAMIC, [matrix] MC sample of entries in steady state and dynamic model derivatives (stacked vertically)
% * STO_si_dDYNAMIC, [matrix] MC sample of derivatives of steady state and dynamic derivatives
% * STO_si_dREDUCEDFORM, [matrix] MC sample of derivatives of steady state and reduced form model solution
% * STO_si_dMOMENTS [matrix] MC sample of Iskrev (2010)'s J matrix
% * STO_dSPECTRUM [matrix] MC sample of Qu and Tkachenko (2012)'s \bar{G} matrix
% * STO_dMINIMAL [matrix] MC sample of Komunjer and Ng (2011)'s \bar{\Delta} matrix
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% -------------------------------------------------------------------------
% This function is called by
% * driver.m
% * gsa.map_identification.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
% -------------------------------------------------------------------------
% This function calls
% * checkpath
% * identification.display
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
% * dyn_waitbar
% * dyn_waitbar_close
% * get_all_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
% * get_posterior_parameters
% * get_the_name
% * identification.analysis
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * isoctave
% * identification.plot
% * dprior.draw
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% * set_default_option
% * set_prior
% * skipline
% * vnorm
% =========================================================================
% Copyright © 2010-2023 Dynare Team
%
% 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
% =========================================================================
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
fname = M_.fname; %model name
dname = M_.dname; %model name
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
%turn warnings off, either globally or only relevant ids
if isoctave
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
%warning('off'),
warning('off','Octave:singular-matrix');
warning('off','Octave:nearly-singular-matrix');
warning('off','Octave:neg-dim-as-zero');
warning('off','Octave:array-as-logical');
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
%warning off;
warning('off','MATLAB:rankDeficientMatrix');
warning('off','MATLAB:singularMatrix');
warning('off','MATLAB:nearlySingularMatrix');
warning('off','MATLAB:plot:IgnoreImaginaryXYPart');
warning('off','MATLAB:specgraph:private:specgraph:UsingOnlyRealComponentOfComplexData');
warning('off','MATLAB:handle_graphics:exceptions:SceneNode');
warning('off','MATLAB:log:logOfZero');
end
2020-01-16 14:43:39 +01:00
%% Set all options in options_ident and create objects
options_ident = set_default_option(options_ident,'gsa_sample_file',0);
2020-01-16 14:43:39 +01:00
% 0: do not use sample file
% 1: triggers gsa prior sample
% 2: triggers gsa Monte-Carlo sample (i.e. loads a sample corresponding to pprior=0 and ppost=0 in sensitivity.run options)
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
% FILENAME: use sample file in provided path
options_ident = set_default_option(options_ident,'parameter_set','prior_mean');
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
% 'calibration': use values in M_.params and M_.Sigma_e to update estimated stderr, corr and model parameters (get_all_parameters)
% 'prior_mode': use values in bayestopt_.p5 prior to update estimated stderr, corr and model parameters
% 'prior_mean': use values in bayestopt_.p1 prior to update estimated stderr, corr and model parameters
% 'posterior_mode': use posterior mode values in estim_params_ to update estimated stderr, corr and model parameters (get_posterior_parameters('mode',...))
% 'posterior_mean': use posterior mean values in estim_params_ to update estimated stderr, corr and model parameters (get_posterior_parameters('mean',...))
% 'posterior_median': use posterior median values in estim_params_ to update estimated stderr, corr and model parameters (get_posterior_parameters('median',...))
options_ident = set_default_option(options_ident,'load_ident_files',0);
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
% 1: load previously computed analysis from identification/fname_identif.mat
options_ident = set_default_option(options_ident,'useautocorr',0);
2020-01-16 14:43:39 +01:00
% 1: use autocorrelations in Iskrev (2010)'s theoretical second moments criteria
% 0: use autocovariances in Iskrev (2010)'s theoretical second moments criteria
options_ident = set_default_option(options_ident,'ar',1);
% number of lags to consider for autocovariances/autocorrelations in Iskrev (2010)'s criteria
options_ident = set_default_option(options_ident,'prior_mc',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
% size of Monte-Carlo sample of parameter draws
options_ident = set_default_option(options_ident,'prior_range',0);
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
% 1: sample uniformly from prior ranges implied by the prior specifications (overwrites prior shape when prior_mc > 1)
% 0: sample from specified prior distributions (when prior_mc > 1)
options_ident = set_default_option(options_ident,'periods',300);
2020-01-16 14:43:39 +01:00
% length of stochastic simulation to compute simulated moment uncertainty (when analytic Hessian is not available)
options_ident = set_default_option(options_ident,'replic',100);
2020-01-16 14:43:39 +01:00
% number of replicas to compute simulated moment uncertainty (when analytic Hessian is not available)
options_ident = set_default_option(options_ident,'advanced',0);
% 1: show a more detailed analysis based on reduced-form model solution and dynamic model derivatives. Further, performs a brute force
% search of the groups of parameters best reproducing the behavior of each single parameter.
options_ident = set_default_option(options_ident,'normalize_jacobians',1);
% 1: normalize Jacobians by either rescaling each row by its largest element in absolute value or for Gram (or Hessian-type) matrices by transforming into correlation-type matrices
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident = set_default_option(options_ident,'grid_nbr',5000);
% number of grid points in [-pi;pi] to approximate the integral to compute Qu and Tkachenko (2012)'s criteria
2020-01-16 14:43:39 +01:00
% note that grid_nbr needs to be even and actually we use (grid_nbr+1) points, as we add the 0 frequency and use symmetry
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 mod(options_ident.grid_nbr,2) ~= 0
options_ident.grid_nbr = options_ident.grid_nbr+1;
fprintf('IDENTIFICATION: ''grid_nbr'' needs to be even, hence it is reset to %d\n',options_ident.grid_nbr)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if mod(options_ident.grid_nbr,2) ~= 0
error('IDENTIFICATION: You need to set an even value for ''grid_nbr''');
end
end
options_ident = set_default_option(options_ident,'tol_rank','robust');
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
% tolerance level used for rank computations
options_ident = set_default_option(options_ident,'tol_deriv',1.e-8);
% tolerance level for selecting columns of non-zero derivatives
options_ident = set_default_option(options_ident,'tol_sv',1.e-3);
% tolerance level for selecting non-zero singular values in identification.checks.m
options_ident = set_default_option(options_ident,'schur_vec_tol',1e-11);
% tolerance level used to find nonstationary variables in Schur decomposition of the transition matrix.
2020-01-16 14:43:39 +01:00
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%check whether to compute identification strength based on information matrix
if ~isfield(options_ident,'no_identification_strength')
options_ident.no_identification_strength = 0;
else
options_ident.no_identification_strength = 1;
end
%check whether to compute and display identification criteria based on steady state and reduced-form model solution
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 ~isfield(options_ident,'no_identification_reducedform')
options_ident.no_identification_reducedform = 0;
else
options_ident.no_identification_reducedform = 1;
end
%check whether to compute and display identification criteria based on Iskrev (2010), i.e. derivative of first two moments
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
if ~isfield(options_ident,'no_identification_moments')
options_ident.no_identification_moments = 0;
else
options_ident.no_identification_moments = 1;
end
%check whether to compute and display identification criteria based on Komunjer and Ng (2011), i.e. derivative of first moment, minimal state space system and observational equivalent spectral density transformation
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 ~isfield(options_ident,'no_identification_minimal')
options_ident.no_identification_minimal = 0;
else
options_ident.no_identification_minimal = 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
%Check whether to compute and display identification criteria based on Qu and Tkachenko (2012), i.e. Gram matrix of derivatives of first moment plus outer product of derivatives of spectral density
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 ~isfield(options_ident,'no_identification_spectrum')
options_ident.no_identification_spectrum = 0;
else
options_ident.no_identification_spectrum = 1;
end
2020-01-16 14:43:39 +01:00
%overwrite setting, as identification strength and advanced need both reducedform and moments criteria
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 (isfield(options_ident,'no_identification_strength') && options_ident.no_identification_strength == 0) || (options_ident.advanced == 1)
options_ident.no_identification_reducedform = 0;
options_ident.no_identification_moments = 0;
end
%overwrite setting, as sensitivity.run does not make use of spectrum and minimal system
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 isfield(options_,'opt_gsa') && isfield(options_.opt_gsa,'identification') && options_.opt_gsa.identification == 1
options_ident.no_identification_minimal = 1;
options_ident.no_identification_spectrum = 1;
end
%Deal with non-stationary cases
2020-01-16 14:43:39 +01:00
if isfield(options_ident,'diffuse_filter')
options_ident.lik_init=3; %overwrites any other lik_init set
options_.diffuse_filter=options_ident.diffuse_filter; %make options_ inherit diffuse filter; will overwrite any conflicting lik_init in dynare_estimation_init
else
if options_.diffuse_filter==1 %warning if estimation with diffuse filter was done, but not passed
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
fprintf('WARNING IDENTIFICATION: Previously the diffuse_filter option was used, but it was not passed to the identification command. This may result in problems if your model contains unit roots.\n');
end
end
options_ident = set_default_option(options_ident,'lik_init',1);
options_.lik_init=options_ident.lik_init; %make options_ inherit lik_init
if options_ident.lik_init==3 %user specified diffuse filter using the lik_init option
options_ident.analytic_derivation=0; %diffuse filter not compatible with analytic derivation
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
% Type of initialization of Kalman filter:
% 1: stationary models: initial matrix of variance of error of forecast is set equal to the unconditional variance of the state variables
% 2: nonstationary models: wide prior is used with an initial matrix of variance of the error of forecast diagonal with 10 on the diagonal (follows the suggestion of Harvey and Phillips(1979))
% 3: nonstationary models: use a diffuse filter (use rather the diffuse_filter option)
% 4: filter is initialized with the fixed point of the Riccati equation
% 5: i) option 2 for non-stationary elements by setting their initial variance in the forecast error matrix to 10 on the diagonal and all co-variances to 0 and
% ii) option 1 for the stationary elements
options_ident = set_default_option(options_ident,'analytic_derivation',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
% 1: analytic derivation of gradient and hessian of likelihood in dsge_likelihood.m, only works for stationary models, i.e. kalman_algo<3
options_ident = set_default_option(options_ident,'order',1);
% 1: first-order perturbation approximation, identification is based on linear state space system
% 2: second-order perturbation approximation, identification is based on second-order pruned state space system
2020-01-16 14:43:39 +01:00
% 3: third-order perturbation approximation, identification is based on third-order pruned state space system
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
%overwrite values in options_, note that options_ is restored at the end of the function
if isfield(options_ident,'prior_trunc')
options_.prior_trunc=options_ident.prior_trunc;
% sets truncation of prior
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
if isfield(options_ident,'TeX')
options_.TeX=options_ident.TeX;
% requests printing of results and graphs in LaTeX
end
2017-05-16 12:42:01 +02:00
if isfield(options_ident,'nograph')
options_.nograph=options_ident.nograph;
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
% do not display and do not save graphs
end
2017-05-16 12:42:01 +02:00
if isfield(options_ident,'nodisplay')
options_.nodisplay=options_ident.nodisplay;
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
% do not display, but save graphs
end
2017-05-16 12:42:01 +02:00
if isfield(options_ident,'graph_format')
options_.graph_format=options_ident.graph_format;
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
% specify file formats to save graphs: eps, pdf, fig, none (do not save but only display)
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% check for external draws, i.e. set pdraws0 for a gsa analysis
2017-05-16 12:42:01 +02:00
if options_ident.gsa_sample_file
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
GSAFolder = checkpath('gsa',dname);
2017-05-16 12:42:01 +02:00
if options_ident.gsa_sample_file==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
load([GSAFolder,filesep,fname,'_prior'],'lpmat','lpmat0','istable');
2017-05-16 12:42:01 +02:00
elseif options_ident.gsa_sample_file==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
load([GSAFolder,filesep,fname,'_mc'],'lpmat','lpmat0','istable');
else
load([GSAFolder,filesep,options_ident.gsa_sample_file],'lpmat','lpmat0','istable');
end
2017-05-16 12:42:01 +02:00
if isempty(istable)
istable=1:size(lpmat,1);
end
2017-05-16 12:42:01 +02:00
if ~isempty(lpmat0)
lpmatx=lpmat0(istable,:);
else
lpmatx=[];
end
pdraws0 = [lpmatx lpmat(istable,:)];
clear lpmat lpmat0 istable;
elseif nargin==6
pdraws0=[];
end
external_sample=0;
if nargin==7 || ~isempty(pdraws0)
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
% change settings if there is an external sample provided as input argument
options_ident.prior_mc = size(pdraws0,1);
options_ident.load_ident_files = 0;
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
external_sample = 1;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% Check if estimated_params block is provided
2017-05-16 12:42:01 +02:00
if isempty(estim_params_)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
prior_exist = 0;
%reset some options
options_ident.prior_mc = 1;
options_ident.prior_range = 0;
options_.identification_check_endogenous_params_with_no_prior = true; %needed to trigger endogenous steady state parameter check in dynare_estimation_init
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
prior_exist = 1;
parameters = options_ident.parameter_set;
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
% overwrite settings in options_ and prepare to call dynare_estimation_init
options_.order = options_ident.order;
if options_ident.order > 1
%order>1 is not compatible with analytic derivation in dsge_likelihood.m
options_ident.analytic_derivation=0;
%order>1 is based on pruned state space system
options_.pruning = true;
end
if options_ident.order == 3
options_.k_order_solver = 1;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_.ar = options_ident.ar;
options_.prior_mc = options_ident.prior_mc;
options_.schur_vec_tol = options_ident.schur_vec_tol;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_.nomoments = 0;
options_.analytic_derivation=options_ident.analytic_derivation;
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
% 1: analytic derivation of gradient and hessian of likelihood in dsge_likelihood.m, only works for stationary models, i.e. kalman_algo<3
options_ = set_default_option(options_,'datafile','');
options_.mode_compute = 0;
options_.plot_priors = 0;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_.smoother = 1;
options_.options_ident = [];
2023-12-18 07:48:27 +01:00
[~, dataset_info, ~, ~, M_, options_, oo_, estim_params_, bayestopt_] = dynare_estimation_init(M_.endo_names, fname, 1, M_, options_, oo_, estim_params_, bayestopt_);
2020-01-16 14:43:39 +01:00
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% set method to compute identification Jacobians (kronflag). Default:0
options_ident = set_default_option(options_ident,'analytic_derivation_mode', options_.analytic_derivation_mode); % if not set by user, inherit default global one
% 0: efficient sylvester equation method to compute analytical derivatives as in Ratto & Iskrev (2012)
% 1: kronecker products method to compute analytical derivatives as in Iskrev (2010) (only for order=1)
% -1: numerical two-sided finite difference method to compute numerical derivatives of all identification Jacobians using function identification.numerical_objective.m (previously thet2tau.m)
2020-01-16 14:43:39 +01:00
% -2: numerical two-sided finite difference method to compute numerically dYss, dg1, dg2, dg3, d2Yss and d2g1, the identification Jacobians are then computed analytically as with 0
if options_.discretionary_policy || options_.ramsey_policy
if options_ident.analytic_derivation_mode~=-1
fprintf('identification.run: discretionary_policy and ramsey_policy require analytic_derivation_mode=-1. Resetting the option.')
options_ident.analytic_derivation_mode=-1;
end
end
2020-01-16 14:43:39 +01:00
options_.analytic_derivation_mode = options_ident.analytic_derivation_mode; %overwrite setting in options_
% Instantiate dprior object (Prior)
if prior_exist
if any(bayestopt_.pshape > 0)
if options_ident.prior_range
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
%sample uniformly from prior ranges (overwrite prior specification)
Prior = dprior(bayestopt_, options_.prior_trunc, true);
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
%sample from prior distributions
Prior = dprior(bayestopt_, options_.prior_trunc, false);
end
else
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.prior_mc = 1; %only one single point
end
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% check if identification directory is already created
IdentifDirectoryName = CheckPath('identification',dname);
% Create indices for stderr, corr and model parameters
if prior_exist % use estimated_params block
indpmodel = []; %initialize index for model parameters
2017-05-16 12:42:01 +02:00
if ~isempty(estim_params_.param_vals)
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
indpmodel = estim_params_.param_vals(:,1); %values correspond to parameters declaration order, row number corresponds to order in estimated_params
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
indpstderr=[]; %initialize index for stderr parameters
if ~isempty(estim_params_.var_exo)
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
indpstderr = estim_params_.var_exo(:,1); %values correspond to varexo declaration order, row number corresponds to order in estimated_params
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
indpcorr=[]; %initialize matrix for corr paramters
if ~isempty(estim_params_.corrx)
indpcorr = estim_params_.corrx(:,1:2); %values correspond to varexo declaration order, row number corresponds to order in estimated_params
end
totparam_nbr = length(bayestopt_.name); % number of estimated stderr, corr and model parameters as declared in estimated_params
2020-01-16 14:43:39 +01:00
modparam_nbr = estim_params_.np; % number of model parameters as declared in estimated_params
stderrparam_nbr = estim_params_.nvx; % number of stderr parameters
corrparam_nbr = estim_params_.ncx; % number of 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
if estim_params_.nvn || estim_params_.ncn %nvn is number of stderr parameters and ncn is number of corr parameters of measurement innovations as declared in estimated_params
2020-01-16 14:43:39 +01:00
error('Identification does not (yet) support measurement errors. Instead, define them explicitly as varexo and provide measurement equations in the model definition.')
end
2020-01-16 14:43:39 +01:00
name = cell(totparam_nbr,1); %initialize cell for parameter names
name_tex = cell(totparam_nbr,1); %initialize cell for TeX parameter names
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 jj=1:totparam_nbr
if options_.TeX
[param_name_temp, param_name_tex_temp]= get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
2023-11-21 02:29:54 +01:00
name_tex{jj,1} =param_name_tex_temp;
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
name{jj,1} = param_name_temp; %ordering corresponds to estimated_params
else
param_name_temp = get_the_name(jj,options_.TeX,M_,estim_params_,options_.varobs);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
name{jj,1} = param_name_temp; %ordering corresponds to estimated_params
end
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else % no estimated_params block, choose all model parameters and all stderr parameters, but no corr parameters
2020-01-16 14:43:39 +01:00
indpmodel = 1:M_.param_nbr; %all model 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
indpstderr = 1:M_.exo_nbr; %all stderr parameters
2020-01-16 14:43:39 +01:00
indpcorr = []; %no 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
stderrparam_nbr = M_.exo_nbr;
corrparam_nbr = 0;
modparam_nbr = M_.param_nbr;
totparam_nbr = modparam_nbr+stderrparam_nbr;
name = cellfun(@(x) horzcat('SE_', x), M_.exo_names, 'UniformOutput', false); %names for stderr parameters
name = vertcat(name, M_.param_names);
2023-11-21 02:29:54 +01:00
name_tex = cellfun(@(x) horzcat('$ SE_{', x, '} $'), M_.exo_names_tex, 'UniformOutput', false);
name_tex = vertcat(name_tex, cellfun(@(x) horzcat('$ ', x, ' $'), M_.param_names_tex, 'UniformOutput', false));
if ~isequal(M_.H,0)
fprintf('\nidentification.run:: Identification does not support measurement errors (yet) and will ignore them in the following. To test their identifiability, instead define them explicitly as varexo and provide measurement equations in the model definition.\n')
end
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
options_ident.name_tex = name_tex;
2020-01-16 14:43:39 +01:00
fprintf('\n======== Identification Analysis ========\n')
if options_ident.order > 1
2020-01-16 14:43:39 +01:00
fprintf('Based on Pruned State Space System (order=%d)\n',options_ident.order);
end
skipline()
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 < 2
options_ident.advanced = 0;
2020-01-16 14:43:39 +01:00
fprintf('There is only one parameter to study for identitification. The advanced option is re-set to 0.\n')
end
2020-01-16 14:43:39 +01:00
% settings dependent on number of 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
options_ident = set_default_option(options_ident,'max_dim_cova_group',min([2,totparam_nbr-1]));
options_ident.max_dim_cova_group = min([options_ident.max_dim_cova_group,totparam_nbr-1]);
% In brute force search (identification.bruteforce.m) when advanced=1 this option sets the maximum dimension of groups of parameters that best reproduce the behavior of each single model parameter
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident = set_default_option(options_ident,'checks_via_subsets',0);
% 1: uses identification.checks_via_subsets.m to compute problematic parameter combinations
% 0: uses identification.checks.m to compute problematic parameter combinations [default]
options_ident = set_default_option(options_ident,'max_dim_subsets_groups',min([4,totparam_nbr-1]));
% In identification.checks_via_subsets.m, when checks_via_subsets=1, this option sets the maximum dimension of groups of parameters for which the corresponding rank criteria is checked
Added parameter derivatives of perturbation solution up to 3 order # Preliminary comments I finished the identification toolbox at orders two and three using the pruned state space system, but before I merge request this, I decided to first merge the new functionality to compute parameter derivatives of perturbation solution matrices at higher orders. So after this is approved, I merge the identification toolbox. I guess @rattoma, @sebastien, and @michel are best choices to review this. I outline the main idea first and then provide some more detailed changes I made to the functions. *** # Main idea This merge request is concerned with the *analytical*computation of the parameter derivatives of first, second and third order perturbation solution matrices, i.e. using _closed-form_ expressions to efficiently compute the derivative of $g_x$ , $g_u$, $g_{xx}$, $g_{xu}$, $g_{uu}$, $g_{\sigma\sigma}$, $g_{xxx}$, $g_{xxu}$, $g_{xuu}$, $g_{uuu}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ *with respect to model parameters* $\theta$. Note that $\theta$ contains model parameters, stderr and corr parameters of shocks. stderr and corr parameters of measurement errors are not yet supported, (they can easily be included as exogenous shocks). The availability of such derivatives is beneficial in terms of more reliable analysis of model sensitivity and parameter identifiability as well as more efficient estimation methods, in particular for models solved up to third order, as it is well-known that numerical derivatives are a tricky business, especially for large models. References for my approach are: * Iskrev (2008, 2010) and Schmitt-Grohé and Uribe (2012, Appendix) who were the first to compute the parameter derivatives analytically at first order, however, using inefficient (sparse) Kronecker products. * Mutschler (2015) who provides the expressions for a second-order, but again using inefficient (sparse) Kronecker products. * Ratto and Iskrev (2012) who show how the first-order system can be solved accurately, fast and efficiently using existing numerical algorithms for generalized Sylvester equations by taking the parameter derivative with respect to each parameter separately. * Julliard and Kamenik (2004) who provide the perturbation solution equation system in tensor notation at any order k. * Levintal (2017) who introduces permutation matrices to express the perturbation solution equation system in matrix notation up to fifth order. Note that @rattoma already implemented the parameter derivatives of $g_x$ and $g_u$ analytically (and numerically), and I rely heavily on his work in `get_first_order_solution_params_derivs.m` (previously `getH.m`). My additions are mainly to this function and thus it is renamed to `get_perturbation_params_derivs.m`. The basic idea of this merge request is to take the second- and third-order perturbation solution systems in Julliard and Kamenik (2004), unfold these into an equivalent matrix representation using permutation matrices as in Levintal (2017). Then extending Ratto and Iskrev (2012) one takes the derivative with respect to each parameter separately and gets a computational problem that is linear, albeit large, as it involves either solving generalized Sylvester equations or taking inverses of highly sparse matrices. I will now briefly summarize the perturbation solution system at third order and the system that results when taking the derivative with respect to parameters. ## Perturbation Solution The following systems arise at first, second, and third order: $(ghx): f_{x} z_{x} = f_{y_{-}^*} + f_{y_0} g_{x} + f_{y_{+}^{**}} g^{**}_{x} g^{*}_{x}= A g_{x} + f_{y_{-}^*}=0$ $(ghu): f_{z} z_{u} = f_{y_0} g_{u} + f_{y_{+}^{**}} g^{**}_{x} g^{*}_{u} + f_{u}= A g_u + f_u = 0$ $(ghxx) : A g_{xx} + B g_{xx} \left(g^{*}_{x} \otimes g^{*}_{x}\right) + f_{zz} \left( z_{x} \otimes z_{x} \right) = 0$ $(ghxu) : A g_{xu} + B g_{xx} \left(g^{*}_{x} \otimes g^{*}_{u}\right) + f_{zz} \left( z_{x} \otimes z_{u} \right) = 0$ $(ghuu) : A g_{uu} + B g_{xx} \left(g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zz} \left( z_{u} \otimes z_{u} \right) = 0$ $(ghs2) : (A+B) g_{\sigma\sigma} + \left( f_{y^{**}_{+}y^{**}_{+}} \left(g^{**}_{u} \otimes g^{**}_{u}\right) + f_{y^{**}_{+}} g^{**}_{uu}\right)vec(\Sigma) = 0$ $(ghxxx) : A g_{xxx} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{x} \otimes g^{*}_{x}\right) + f_{y_{+}}g^{**}_{xx} \left(g^{*}_x \otimes g^{*}_{xx}\right)P_{x\_xx} + f_{zz} \left( z_{x} \otimes z_{xx} \right)P_{x\_xx} + f_{zzz} \left( z_{x} \otimes z_{x} \otimes z_{x} \right) = 0$ $(ghxxu) : A g_{xxu} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{x} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{x} \otimes z_{x} \otimes z_{u} \right) + f_{zz} \left( \left( z_{x} \otimes z_{xu} \right)P_{x\_xu} + \left(z_{xx} \otimes z_{u}\right) \right) + f_{y_{+}}g^{**}_{xx} \left( \left(g^{*}_{x} \otimes g^{*}_{xu}\right)P_{x\_xu} + \left(g^{*}_{xx} \otimes g^{*}_{u}\right) \right) = 0$ $(ghxuu) : A g_{xuu} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{x} \otimes z_{u} \otimes z_{u} \right)+ f_{zz} \left( \left( z_{xu} \otimes z_{u} \right)P_{xu\_u} + \left(z_{x} \otimes z_{uu}\right) \right) + f_{y_{+}}g^{**}_{xx} \left( \left(g^{*}_{xu} \otimes g^{*}_{u}\right)P_{xu\_u} + \left(g^{*}_{x} \otimes g^{*}_{uu}\right) \right) = 0$ $(ghuuu) : A g_{uuu} + B g_{xxx} \left(g^{*}_{u} \otimes g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{u} \otimes z_{u} \otimes z_{u} \right)+ f_{zz} \left( z_{u} \otimes z_{uu} \right)P_{u\_uu} + f_{y_{+}}g^{**}_{xx} \left(g^{*}_{u} \otimes g^{*}_{uu}\right)P_{u\_uu} = 0$ $(ghx\sigma\sigma) : A g_{x\sigma\sigma} + B g_{x\sigma\sigma} g^{*}_x + f_{y_{+}} g^{**}_{xx}\left(g^{*}_{x} \otimes g^{*}_{\sigma\sigma}\right) + f_{zz} \left(z_{x} \otimes z_{\sigma\sigma}\right) + F_{xu_{+}u_{+}}\left(I_{n_x} \otimes vec(\Sigma)\right) = 0$ $F_{xu_{+}u_{+}} = f_{y_{+}^{\ast\ast}} g_{xuu}^{\ast\ast} (g_x^{\ast} \otimes I_{n_u^2}) + f_{zz} \left( \left( z_{xu_{+}} \otimes z_{u_{+}} \right)P_{xu\_u} + \left(z_{x} \otimes z_{u_{+}u_{+}}\right) \right) + f_{zzz}\left(z_{x} \otimes z_{u_{+}} \otimes z_{u_{+}}\right)$ $(ghu\sigma\sigma) : A g_{u\sigma\sigma} + B g_{x\sigma\sigma} g^{*}_{u} + f_{y_{+}} g^{**}_{xx}\left(g^{*}_{u} \otimes g^{*}_{\sigma\sigma}\right) + f_{zz} \left(z_{u} \otimes z_{\sigma\sigma}\right) + F_{uu_{+}u_{+}}\left(I_{n_u} \otimes vec(\Sigma_u)\right) = 0$ $F_{uu_{+}u_{+}} = f_{y_{+}^{\ast\ast}} g_{xuu}^{\ast\ast} (g_u^{\ast} \otimes I_{n_u^2}) + f_{zz} \left( \left( z_{uu_{+}} \otimes z_{u_{+}} \right)P_{uu\_u} + \left(z_{u} \otimes z_{u_{+}u_{+}}\right) \right) + f_{zzz}\left(z_{u} \otimes z_{u_{+}} \otimes z_{u_{+}}\right)$ A and B are the common perturbation matrices: $A = f_{y_0} + \begin{pmatrix} \underbrace{0}_{n\times n_{static}} &\vdots& \underbrace{f_{y^{**}_{+}} \cdot g^{**}_{x}}_{n \times n_{spred}} &\vdots& \underbrace{0}_{n\times n_{frwd}} \end{pmatrix}$and $B = \begin{pmatrix} \underbrace{0}_{n \times n_{static}}&\vdots & \underbrace{0}_{n \times n_{pred}} & \vdots & \underbrace{f_{y^{**}_{+}}}_{n \times n_{sfwrd}} \end{pmatrix}$ and $z=(y_{-}^{\ast}; y; y_{+}^{\ast\ast}; u)$ denotes the dynamic model variables as in `M_.lead_lag_incidence`, $y^\ast$ denote state variables, $y^{\ast\ast}$ denote forward looking variables, $y_+$ denote the variables with a lead, $y_{-}$ denote variables with a lag, $y_0$ denote variables at period t, $f$ the model equations, and $f_z$ the first-order dynamic model derivatives, $f_{zz}$ the second-order dynamic derivatives, and $f_{zzz}$ the third-order dynamic model derivatives. Then: $z_{x} = \begin{pmatrix}I\\g_{x}\\g^{**}_{x} g^{*}_{x}\\0\end{pmatrix}$, $z_{u} =\begin{pmatrix}0\\g_{u}\\g^{**}_{x} \cdot g^{*}_{u}\\I\end{pmatrix}$, $z_{u_{+}} =\begin{pmatrix}0\\0\\g^{**}_{u}\\0\end{pmatrix}$ $z_{xx} = \begin{pmatrix} 0\\g_{xx}\\g^{**}_{x} \left( g^{*}_x \otimes g^{*}_{x} \right) + g^{**}_{x} g^{*}_{x}\\0\end{pmatrix}$, $z_{xu} =\begin{pmatrix}0\\g_{xu}\\g^{**}_{xx} \left( g^{*}_x \otimes g^{*}_{u} \right) + g^{**}_{x} g^{*}_{xu}\\0\end{pmatrix}$, $z_{uu} =\begin{pmatrix}0\\g_{uu}\\g^{**}_{xx} \left( g^{*}_u \otimes g^{*}_{u} \right) + g^{**}_{x} g^{*}_{uu}\\0\end{pmatrix}$, $z_{xu_{+}} =\begin{pmatrix}0\\0\\g^{**}_{xu} \left( g^{*}_x \otimes I \right)\\0\end{pmatrix}$, $z_{uu_{+}} =\begin{pmatrix}0\\0\\g^{**}_{xu} \left( g^{*}_{u} \otimes I \right)\\0\end{pmatrix}$, $z_{u_{+}u_{+}} =\begin{pmatrix}0\\0\\g^{\ast\ast}_{uu}\\0\end{pmatrix}$, $z_{\sigma\sigma} = \begin{pmatrix}0\\ g_{\sigma\sigma}\\ g^{\ast\ast}_{x}g^{\ast}_{\sigma\sigma} + g^{\ast\ast}_{\sigma\sigma}\\0 \end{pmatrix}$ $P$ are permutation matrices that can be computed using Matlab's `ipermute` function. ## Parameter derivatives of perturbation solutions First, we need the parameter derivatives of first, second, third, and fourth derivatives of the dynamic model (i.e. g1,g2,g3,g4 in dynamic files), I make use of the implicit function theorem: Let $f_{z^k}$ denote the kth derivative (wrt all dynamic variables) of the dynamic model, then let $df_{z^k}$ denote the first-derivative (wrt all model parameters) of $f_{z^k}$ evaluated at the steady state. Note that $f_{z^k}$ is a function of both the model parameters $\theta$ and of the steady state of all dynamic variables $\bar{z}$, which also depend on the parameters. Hence, implicitly $f_{z^k}=f_{z^k}(\theta,\bar{z}(\theta))$ and $df_{z^k}$ consists of two parts: 1. direct derivative wrt to all model parameters given by the preprocessor in the `_params_derivs.m` files 2. contribution of derivative of steady state of dynamic variables (wrt all model parameters): $f_{z^{k+1}} \cdot d\bar{z}$ Note that we already have functionality to compute $d\bar{z}$ analytically. Having this, the above perturbation systems are basically equations of the following types $AX +BXC = RHS$ or $AX = RHS$ Now when taking the derivative (wrt to one single parameter $\theta_j$), we get $A\mathrm{d}\{X\} + B\mathrm{d}\{X\}C = \mathrm{d}\{RHS\} - \mathrm{d}\{A\}X - \mathrm{d}\{B\}XC - BX\mathrm{d}\{C\}$ or $A\mathrm{d}\{X\} = \mathrm{d}\{RHS\} - \mathrm{d}\{A\}X$ The first one is a Sylvester type equation, the second one can be solved by taking the inverse of $A$. The only diffculty and tedious work arrises in computing (the highly sparse) derivatives of $RHS$. *** # New functions: ` ## get_perturbation_params_derivs.m`and `get_perturbation_params_derivs_numerical_objective.m` * The parameter derivatives up to third order are computed in the new function`get_perturbation_params_derivs.m` both analytically and numerically. For numerical derivatives `get_perturbation_params_derivs_numerical_objective.m` is the objective for `fjaco.m` or `hessian_sparse.m` or `hessian.m`. * `get_perturbation_params_derivs.m` is basically an extended version of the previous `get_first_order_solution_params_derivs.m` function. * * `get_perturbation_params_derivs_numerical_objective.m`builds upon `identification_numerical_objective.m`. It is used for numerical derivatives, whenever `analytic_derivation_mode=-1|-2`. It takes from `identification_numerical_objective.m` the parts that compute numerical parameter Jacobians of steady state, dynamic model equations, and perturbation solution matrices. Hence, these parts are removed in `identification_numerical_objective.m` and it only computes numerical parameter Jacobian of moments and spectrum which are needed for identification analysis in `get_identification_jacobians.m`, when `analytic_derivation_mode=-1` only. * Detailed changes: * Most important: notation of this function is now in accordance to the k_order_solver, i.e. we do not compute derivatives of Kalman transition matrices A and B, but rather the solution matrices ghx,ghu,ghxx,ghxu,ghuu,ghs2,ghxxx,ghxxu,ghxuu,ghuuu,ghxss,ghuss in accordance with notation used in `oo_.dr`. As a byproduct at first-order, focusing on ghx and ghu instead of Kalman transition matrices A and B makes the computations slightly faster for large models (e.g. for Quest the computations were faster by a couple of seconds, not much, but okay). * Removed use of `kstate`, see also Dynare/dynare#1653 and Dynare/dynare!1656 * Output arguments are stored in a structure `DERIVS`, there is also a flag `d2flag` that computes parameter hessians needed only in `dsge_likelihood.m`. * Removed `kronflag` as input. `options_.analytic_derivation_mode` is now used instead of `kronflag`. * Removed `indvar`, an index that was used to selected specific variables in the derivatives. This is not needed, as we always compute the parameter derivatives for all variables first and then select a subset of variables. The selection now takes place in other functions, like `dsge_likelihood.m`. * Introduced some checks: (i) deterministic exogenous variables are not supported, (ii) Kronecker method only compatible with first-order approximation so reset to sylvester method, (iii) for purely backward or forward models we need to be careful with the rows in `M_.lead_la g_incidence`, (iv) if `_params_derivs.m` files are missing an error is thrown. * For numerical derivatives, if mod file does not contain an `estimated_params_block`, a temporary one with the most important parameter information is created. ## `unfold_g4.m` * When evaluating g3 and g4 one needs to take into account that these do not contain symmetric elements, so one needs to use `unfold_g3.m` and the new function `unfold_g4.m`. This returns an unfolded version of the same matrix (i.e. with symmetric elements). *** # New test models `.gitignore` and `Makefile.am` are changed accordingly. Also now it is possible to run test suite on analytic_derivatives, i.e. run `make check m/analytic_derivatives` ## `analytic_derivatives/BrockMirman_PertParamsDerivs.mod` * This is the Brock Mirman model, where we know the exact policy function $g$ for capital and consumption. As this does not imply a nonzero $g_{\sigma\sigma}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ I added some artificial equations to get nonzero solution matrices with respect to $\sigma$. The true perturbation solution matrices $g_x$ , $g_u$, $g_{xx}$, $g_{xu}$, $g_{uu}$, $g_{\sigma\sigma}$, $g_{xxx}$, $g_{xxu}$, $g_{xuu}$, $g_{uuu}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ are then computed analytically with Matlab's symbolic toolbox and saved in `nBrockMirmanSYM.mat`. There is a preprocessor flag that recreates these analytical computations if changes are needed (and to check whether I made some errors here ;-) ) * Then solution matrices up to third order and their parameter Jacobians are then compared to the ones computed by Dynare's `k_order_solver` and by `get_perturbation_params_derivs` for all `analytic_derivation_mode`'s. There will be an error if the maximum absolute deviation is too large, i.e. for numerical derivatives (`analytic_derivation_mode=-1|-2`) the tolerance is choosen lower (around 1e-5); for analytical methods we are stricter: around 1e-13 for first-order, 1e-12 for second order, and 1e-11 for third-order. * As a side note, this mod file also checks Dynare's `k_order_solver` algorithm and throws an error if something is wrong. * This test model shows that the new functionality works well. And analytical derivatives perform way better and accurate than numerical ones, even for this small model. ## `analytic_derivatives/burnside_3_order_PertParamsDerivs.mod` * This builds upon `tests/k_order_perturbation/burnside_k_order.mod` and computes the true parameter derivatives analytically by hand. * This test model also shows that the new functionality works well. ## `analytic_derivatives/LindeTrabandt2019.mod` * Shows that the new functionality also works for medium-sized models, i.e. a SW type model solved at third order with 35 variables (11 states). 2 shocks and 20 parameters. * This mod file can be used to tweak the speed of the computations in the future. * Compares numerical versus analytical parameter derivatives (for first, second and third order). Note that this model clearly shows that numerical ones are quite different than analytical ones even at first order! ## `identification/LindeTrabandt2019_xfail.mod` * This model is a check for issue Dynare/dynare#1595, see fjaco.m below, and will fail. * Removed `analytic_derivatives/ls2003.mod` as this mod file is neither in the testsuite nor does it work. *** # Detailed changes in other functions ## `get_first_order_solution_params_derivs.m` * Deleted, or actually, renamed to `get_perturbation_params_derivs.m`, as this function now is able to compute the derivatives up to third order ## `identification_numerical_objective.m` * `get_perturbation_params_derivs_numerical_objective.m`builds upon `identification_numerical_objective.m`. It takes from `identification_numerical_objective.m` the parts that compute numerical parameter Jacobians of steady state, dynamic model equations, and perturbation solution matrices. Hence, these parts are removed in `identification_numerical_objective.m` and it only computes numerical parameter Jacobian of moments and spectrum which are needed for identification analysis in `get_identification_jacobians.m`, when `analytic_derivation_mode=-1` only. ## `dsge_likelihood.m` * As `get_first_order_solution_params_derivs.m`is renamed to `get_perturbation_params_derivs.m`, the call is adapted. That is,`get_perturbation_params_derivs` does not compute the derivatives of the Kalman transition `T`matrix anymore, but instead of the dynare solution matrix `ghx`. So we recreate `T` here as this amounts to adding some zeros and focusing on selected variables only. * Added some checks to make sure the first-order approximation is selected. * Removed `kron_flag` as input, as `get_perturbation_params_derivs` looks into `options_.analytic_derivation_mode` for `kron_flag`. ## `dynare_identification.m` * make sure that setting `analytic_derivation_mode` is set both in `options_ident` and `options_`. Note that at the end of the function we restore the `options_` structure, so all changes are local. In a next merge request, I will remove the global variables to make all variables local. ## `get_identification_jacobians.m` * As `get_first_order_solution_params_derivs.m`is renamed to `get_perturbation_params_derivs.m`, the call is adapted. That is,`get_perturbation_params_derivs` does not compute the derivatives of the Kalman transition `A` and `B` matrix anymore, but instead of the dynare solution matrix `ghx` and `ghu`. So we recreate these matrices here instead of in `get_perturbation_params_derivs.m`. * Added `str2func` for better function handles in `fjaco.m`. ## `fjaco.m` * make `tol`an option, which can be adjusted by changing `options_.dynatol.x`for identification and parameter derivatives purposes. * include a check and an informative error message, if numerical derivatives (two-sided finite difference method) yield errors in `resol.m` for identification and parameter derivatives purposes. This closes issue Dynare/dynare#1595. * Changed year of copyright to 2010-2017,2019 *** # Further suggestions and questions * Ones this is merged, I will merge request an improvement of the identification toolbox, which will work up to third order using the pruned state space. This will also remove some issues and bugs, and also I will remove global variables in this request. * The third-order derivatives can be further improved by taking sparsity into account and use mex versions for kronecker products etc. I leave this for further testing (and if anybody actually uses this ;-) )
2019-12-17 19:17:09 +01:00
2020-01-16 14:43:39 +01:00
% store identification options
options_.options_ident = options_ident;
store_options_ident = options_ident;
Added parameter derivatives of perturbation solution up to 3 order # Preliminary comments I finished the identification toolbox at orders two and three using the pruned state space system, but before I merge request this, I decided to first merge the new functionality to compute parameter derivatives of perturbation solution matrices at higher orders. So after this is approved, I merge the identification toolbox. I guess @rattoma, @sebastien, and @michel are best choices to review this. I outline the main idea first and then provide some more detailed changes I made to the functions. *** # Main idea This merge request is concerned with the *analytical*computation of the parameter derivatives of first, second and third order perturbation solution matrices, i.e. using _closed-form_ expressions to efficiently compute the derivative of $g_x$ , $g_u$, $g_{xx}$, $g_{xu}$, $g_{uu}$, $g_{\sigma\sigma}$, $g_{xxx}$, $g_{xxu}$, $g_{xuu}$, $g_{uuu}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ *with respect to model parameters* $\theta$. Note that $\theta$ contains model parameters, stderr and corr parameters of shocks. stderr and corr parameters of measurement errors are not yet supported, (they can easily be included as exogenous shocks). The availability of such derivatives is beneficial in terms of more reliable analysis of model sensitivity and parameter identifiability as well as more efficient estimation methods, in particular for models solved up to third order, as it is well-known that numerical derivatives are a tricky business, especially for large models. References for my approach are: * Iskrev (2008, 2010) and Schmitt-Grohé and Uribe (2012, Appendix) who were the first to compute the parameter derivatives analytically at first order, however, using inefficient (sparse) Kronecker products. * Mutschler (2015) who provides the expressions for a second-order, but again using inefficient (sparse) Kronecker products. * Ratto and Iskrev (2012) who show how the first-order system can be solved accurately, fast and efficiently using existing numerical algorithms for generalized Sylvester equations by taking the parameter derivative with respect to each parameter separately. * Julliard and Kamenik (2004) who provide the perturbation solution equation system in tensor notation at any order k. * Levintal (2017) who introduces permutation matrices to express the perturbation solution equation system in matrix notation up to fifth order. Note that @rattoma already implemented the parameter derivatives of $g_x$ and $g_u$ analytically (and numerically), and I rely heavily on his work in `get_first_order_solution_params_derivs.m` (previously `getH.m`). My additions are mainly to this function and thus it is renamed to `get_perturbation_params_derivs.m`. The basic idea of this merge request is to take the second- and third-order perturbation solution systems in Julliard and Kamenik (2004), unfold these into an equivalent matrix representation using permutation matrices as in Levintal (2017). Then extending Ratto and Iskrev (2012) one takes the derivative with respect to each parameter separately and gets a computational problem that is linear, albeit large, as it involves either solving generalized Sylvester equations or taking inverses of highly sparse matrices. I will now briefly summarize the perturbation solution system at third order and the system that results when taking the derivative with respect to parameters. ## Perturbation Solution The following systems arise at first, second, and third order: $(ghx): f_{x} z_{x} = f_{y_{-}^*} + f_{y_0} g_{x} + f_{y_{+}^{**}} g^{**}_{x} g^{*}_{x}= A g_{x} + f_{y_{-}^*}=0$ $(ghu): f_{z} z_{u} = f_{y_0} g_{u} + f_{y_{+}^{**}} g^{**}_{x} g^{*}_{u} + f_{u}= A g_u + f_u = 0$ $(ghxx) : A g_{xx} + B g_{xx} \left(g^{*}_{x} \otimes g^{*}_{x}\right) + f_{zz} \left( z_{x} \otimes z_{x} \right) = 0$ $(ghxu) : A g_{xu} + B g_{xx} \left(g^{*}_{x} \otimes g^{*}_{u}\right) + f_{zz} \left( z_{x} \otimes z_{u} \right) = 0$ $(ghuu) : A g_{uu} + B g_{xx} \left(g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zz} \left( z_{u} \otimes z_{u} \right) = 0$ $(ghs2) : (A+B) g_{\sigma\sigma} + \left( f_{y^{**}_{+}y^{**}_{+}} \left(g^{**}_{u} \otimes g^{**}_{u}\right) + f_{y^{**}_{+}} g^{**}_{uu}\right)vec(\Sigma) = 0$ $(ghxxx) : A g_{xxx} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{x} \otimes g^{*}_{x}\right) + f_{y_{+}}g^{**}_{xx} \left(g^{*}_x \otimes g^{*}_{xx}\right)P_{x\_xx} + f_{zz} \left( z_{x} \otimes z_{xx} \right)P_{x\_xx} + f_{zzz} \left( z_{x} \otimes z_{x} \otimes z_{x} \right) = 0$ $(ghxxu) : A g_{xxu} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{x} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{x} \otimes z_{x} \otimes z_{u} \right) + f_{zz} \left( \left( z_{x} \otimes z_{xu} \right)P_{x\_xu} + \left(z_{xx} \otimes z_{u}\right) \right) + f_{y_{+}}g^{**}_{xx} \left( \left(g^{*}_{x} \otimes g^{*}_{xu}\right)P_{x\_xu} + \left(g^{*}_{xx} \otimes g^{*}_{u}\right) \right) = 0$ $(ghxuu) : A g_{xuu} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{x} \otimes z_{u} \otimes z_{u} \right)+ f_{zz} \left( \left( z_{xu} \otimes z_{u} \right)P_{xu\_u} + \left(z_{x} \otimes z_{uu}\right) \right) + f_{y_{+}}g^{**}_{xx} \left( \left(g^{*}_{xu} \otimes g^{*}_{u}\right)P_{xu\_u} + \left(g^{*}_{x} \otimes g^{*}_{uu}\right) \right) = 0$ $(ghuuu) : A g_{uuu} + B g_{xxx} \left(g^{*}_{u} \otimes g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{u} \otimes z_{u} \otimes z_{u} \right)+ f_{zz} \left( z_{u} \otimes z_{uu} \right)P_{u\_uu} + f_{y_{+}}g^{**}_{xx} \left(g^{*}_{u} \otimes g^{*}_{uu}\right)P_{u\_uu} = 0$ $(ghx\sigma\sigma) : A g_{x\sigma\sigma} + B g_{x\sigma\sigma} g^{*}_x + f_{y_{+}} g^{**}_{xx}\left(g^{*}_{x} \otimes g^{*}_{\sigma\sigma}\right) + f_{zz} \left(z_{x} \otimes z_{\sigma\sigma}\right) + F_{xu_{+}u_{+}}\left(I_{n_x} \otimes vec(\Sigma)\right) = 0$ $F_{xu_{+}u_{+}} = f_{y_{+}^{\ast\ast}} g_{xuu}^{\ast\ast} (g_x^{\ast} \otimes I_{n_u^2}) + f_{zz} \left( \left( z_{xu_{+}} \otimes z_{u_{+}} \right)P_{xu\_u} + \left(z_{x} \otimes z_{u_{+}u_{+}}\right) \right) + f_{zzz}\left(z_{x} \otimes z_{u_{+}} \otimes z_{u_{+}}\right)$ $(ghu\sigma\sigma) : A g_{u\sigma\sigma} + B g_{x\sigma\sigma} g^{*}_{u} + f_{y_{+}} g^{**}_{xx}\left(g^{*}_{u} \otimes g^{*}_{\sigma\sigma}\right) + f_{zz} \left(z_{u} \otimes z_{\sigma\sigma}\right) + F_{uu_{+}u_{+}}\left(I_{n_u} \otimes vec(\Sigma_u)\right) = 0$ $F_{uu_{+}u_{+}} = f_{y_{+}^{\ast\ast}} g_{xuu}^{\ast\ast} (g_u^{\ast} \otimes I_{n_u^2}) + f_{zz} \left( \left( z_{uu_{+}} \otimes z_{u_{+}} \right)P_{uu\_u} + \left(z_{u} \otimes z_{u_{+}u_{+}}\right) \right) + f_{zzz}\left(z_{u} \otimes z_{u_{+}} \otimes z_{u_{+}}\right)$ A and B are the common perturbation matrices: $A = f_{y_0} + \begin{pmatrix} \underbrace{0}_{n\times n_{static}} &\vdots& \underbrace{f_{y^{**}_{+}} \cdot g^{**}_{x}}_{n \times n_{spred}} &\vdots& \underbrace{0}_{n\times n_{frwd}} \end{pmatrix}$and $B = \begin{pmatrix} \underbrace{0}_{n \times n_{static}}&\vdots & \underbrace{0}_{n \times n_{pred}} & \vdots & \underbrace{f_{y^{**}_{+}}}_{n \times n_{sfwrd}} \end{pmatrix}$ and $z=(y_{-}^{\ast}; y; y_{+}^{\ast\ast}; u)$ denotes the dynamic model variables as in `M_.lead_lag_incidence`, $y^\ast$ denote state variables, $y^{\ast\ast}$ denote forward looking variables, $y_+$ denote the variables with a lead, $y_{-}$ denote variables with a lag, $y_0$ denote variables at period t, $f$ the model equations, and $f_z$ the first-order dynamic model derivatives, $f_{zz}$ the second-order dynamic derivatives, and $f_{zzz}$ the third-order dynamic model derivatives. Then: $z_{x} = \begin{pmatrix}I\\g_{x}\\g^{**}_{x} g^{*}_{x}\\0\end{pmatrix}$, $z_{u} =\begin{pmatrix}0\\g_{u}\\g^{**}_{x} \cdot g^{*}_{u}\\I\end{pmatrix}$, $z_{u_{+}} =\begin{pmatrix}0\\0\\g^{**}_{u}\\0\end{pmatrix}$ $z_{xx} = \begin{pmatrix} 0\\g_{xx}\\g^{**}_{x} \left( g^{*}_x \otimes g^{*}_{x} \right) + g^{**}_{x} g^{*}_{x}\\0\end{pmatrix}$, $z_{xu} =\begin{pmatrix}0\\g_{xu}\\g^{**}_{xx} \left( g^{*}_x \otimes g^{*}_{u} \right) + g^{**}_{x} g^{*}_{xu}\\0\end{pmatrix}$, $z_{uu} =\begin{pmatrix}0\\g_{uu}\\g^{**}_{xx} \left( g^{*}_u \otimes g^{*}_{u} \right) + g^{**}_{x} g^{*}_{uu}\\0\end{pmatrix}$, $z_{xu_{+}} =\begin{pmatrix}0\\0\\g^{**}_{xu} \left( g^{*}_x \otimes I \right)\\0\end{pmatrix}$, $z_{uu_{+}} =\begin{pmatrix}0\\0\\g^{**}_{xu} \left( g^{*}_{u} \otimes I \right)\\0\end{pmatrix}$, $z_{u_{+}u_{+}} =\begin{pmatrix}0\\0\\g^{\ast\ast}_{uu}\\0\end{pmatrix}$, $z_{\sigma\sigma} = \begin{pmatrix}0\\ g_{\sigma\sigma}\\ g^{\ast\ast}_{x}g^{\ast}_{\sigma\sigma} + g^{\ast\ast}_{\sigma\sigma}\\0 \end{pmatrix}$ $P$ are permutation matrices that can be computed using Matlab's `ipermute` function. ## Parameter derivatives of perturbation solutions First, we need the parameter derivatives of first, second, third, and fourth derivatives of the dynamic model (i.e. g1,g2,g3,g4 in dynamic files), I make use of the implicit function theorem: Let $f_{z^k}$ denote the kth derivative (wrt all dynamic variables) of the dynamic model, then let $df_{z^k}$ denote the first-derivative (wrt all model parameters) of $f_{z^k}$ evaluated at the steady state. Note that $f_{z^k}$ is a function of both the model parameters $\theta$ and of the steady state of all dynamic variables $\bar{z}$, which also depend on the parameters. Hence, implicitly $f_{z^k}=f_{z^k}(\theta,\bar{z}(\theta))$ and $df_{z^k}$ consists of two parts: 1. direct derivative wrt to all model parameters given by the preprocessor in the `_params_derivs.m` files 2. contribution of derivative of steady state of dynamic variables (wrt all model parameters): $f_{z^{k+1}} \cdot d\bar{z}$ Note that we already have functionality to compute $d\bar{z}$ analytically. Having this, the above perturbation systems are basically equations of the following types $AX +BXC = RHS$ or $AX = RHS$ Now when taking the derivative (wrt to one single parameter $\theta_j$), we get $A\mathrm{d}\{X\} + B\mathrm{d}\{X\}C = \mathrm{d}\{RHS\} - \mathrm{d}\{A\}X - \mathrm{d}\{B\}XC - BX\mathrm{d}\{C\}$ or $A\mathrm{d}\{X\} = \mathrm{d}\{RHS\} - \mathrm{d}\{A\}X$ The first one is a Sylvester type equation, the second one can be solved by taking the inverse of $A$. The only diffculty and tedious work arrises in computing (the highly sparse) derivatives of $RHS$. *** # New functions: ` ## get_perturbation_params_derivs.m`and `get_perturbation_params_derivs_numerical_objective.m` * The parameter derivatives up to third order are computed in the new function`get_perturbation_params_derivs.m` both analytically and numerically. For numerical derivatives `get_perturbation_params_derivs_numerical_objective.m` is the objective for `fjaco.m` or `hessian_sparse.m` or `hessian.m`. * `get_perturbation_params_derivs.m` is basically an extended version of the previous `get_first_order_solution_params_derivs.m` function. * * `get_perturbation_params_derivs_numerical_objective.m`builds upon `identification_numerical_objective.m`. It is used for numerical derivatives, whenever `analytic_derivation_mode=-1|-2`. It takes from `identification_numerical_objective.m` the parts that compute numerical parameter Jacobians of steady state, dynamic model equations, and perturbation solution matrices. Hence, these parts are removed in `identification_numerical_objective.m` and it only computes numerical parameter Jacobian of moments and spectrum which are needed for identification analysis in `get_identification_jacobians.m`, when `analytic_derivation_mode=-1` only. * Detailed changes: * Most important: notation of this function is now in accordance to the k_order_solver, i.e. we do not compute derivatives of Kalman transition matrices A and B, but rather the solution matrices ghx,ghu,ghxx,ghxu,ghuu,ghs2,ghxxx,ghxxu,ghxuu,ghuuu,ghxss,ghuss in accordance with notation used in `oo_.dr`. As a byproduct at first-order, focusing on ghx and ghu instead of Kalman transition matrices A and B makes the computations slightly faster for large models (e.g. for Quest the computations were faster by a couple of seconds, not much, but okay). * Removed use of `kstate`, see also Dynare/dynare#1653 and Dynare/dynare!1656 * Output arguments are stored in a structure `DERIVS`, there is also a flag `d2flag` that computes parameter hessians needed only in `dsge_likelihood.m`. * Removed `kronflag` as input. `options_.analytic_derivation_mode` is now used instead of `kronflag`. * Removed `indvar`, an index that was used to selected specific variables in the derivatives. This is not needed, as we always compute the parameter derivatives for all variables first and then select a subset of variables. The selection now takes place in other functions, like `dsge_likelihood.m`. * Introduced some checks: (i) deterministic exogenous variables are not supported, (ii) Kronecker method only compatible with first-order approximation so reset to sylvester method, (iii) for purely backward or forward models we need to be careful with the rows in `M_.lead_la g_incidence`, (iv) if `_params_derivs.m` files are missing an error is thrown. * For numerical derivatives, if mod file does not contain an `estimated_params_block`, a temporary one with the most important parameter information is created. ## `unfold_g4.m` * When evaluating g3 and g4 one needs to take into account that these do not contain symmetric elements, so one needs to use `unfold_g3.m` and the new function `unfold_g4.m`. This returns an unfolded version of the same matrix (i.e. with symmetric elements). *** # New test models `.gitignore` and `Makefile.am` are changed accordingly. Also now it is possible to run test suite on analytic_derivatives, i.e. run `make check m/analytic_derivatives` ## `analytic_derivatives/BrockMirman_PertParamsDerivs.mod` * This is the Brock Mirman model, where we know the exact policy function $g$ for capital and consumption. As this does not imply a nonzero $g_{\sigma\sigma}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ I added some artificial equations to get nonzero solution matrices with respect to $\sigma$. The true perturbation solution matrices $g_x$ , $g_u$, $g_{xx}$, $g_{xu}$, $g_{uu}$, $g_{\sigma\sigma}$, $g_{xxx}$, $g_{xxu}$, $g_{xuu}$, $g_{uuu}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ are then computed analytically with Matlab's symbolic toolbox and saved in `nBrockMirmanSYM.mat`. There is a preprocessor flag that recreates these analytical computations if changes are needed (and to check whether I made some errors here ;-) ) * Then solution matrices up to third order and their parameter Jacobians are then compared to the ones computed by Dynare's `k_order_solver` and by `get_perturbation_params_derivs` for all `analytic_derivation_mode`'s. There will be an error if the maximum absolute deviation is too large, i.e. for numerical derivatives (`analytic_derivation_mode=-1|-2`) the tolerance is choosen lower (around 1e-5); for analytical methods we are stricter: around 1e-13 for first-order, 1e-12 for second order, and 1e-11 for third-order. * As a side note, this mod file also checks Dynare's `k_order_solver` algorithm and throws an error if something is wrong. * This test model shows that the new functionality works well. And analytical derivatives perform way better and accurate than numerical ones, even for this small model. ## `analytic_derivatives/burnside_3_order_PertParamsDerivs.mod` * This builds upon `tests/k_order_perturbation/burnside_k_order.mod` and computes the true parameter derivatives analytically by hand. * This test model also shows that the new functionality works well. ## `analytic_derivatives/LindeTrabandt2019.mod` * Shows that the new functionality also works for medium-sized models, i.e. a SW type model solved at third order with 35 variables (11 states). 2 shocks and 20 parameters. * This mod file can be used to tweak the speed of the computations in the future. * Compares numerical versus analytical parameter derivatives (for first, second and third order). Note that this model clearly shows that numerical ones are quite different than analytical ones even at first order! ## `identification/LindeTrabandt2019_xfail.mod` * This model is a check for issue Dynare/dynare#1595, see fjaco.m below, and will fail. * Removed `analytic_derivatives/ls2003.mod` as this mod file is neither in the testsuite nor does it work. *** # Detailed changes in other functions ## `get_first_order_solution_params_derivs.m` * Deleted, or actually, renamed to `get_perturbation_params_derivs.m`, as this function now is able to compute the derivatives up to third order ## `identification_numerical_objective.m` * `get_perturbation_params_derivs_numerical_objective.m`builds upon `identification_numerical_objective.m`. It takes from `identification_numerical_objective.m` the parts that compute numerical parameter Jacobians of steady state, dynamic model equations, and perturbation solution matrices. Hence, these parts are removed in `identification_numerical_objective.m` and it only computes numerical parameter Jacobian of moments and spectrum which are needed for identification analysis in `get_identification_jacobians.m`, when `analytic_derivation_mode=-1` only. ## `dsge_likelihood.m` * As `get_first_order_solution_params_derivs.m`is renamed to `get_perturbation_params_derivs.m`, the call is adapted. That is,`get_perturbation_params_derivs` does not compute the derivatives of the Kalman transition `T`matrix anymore, but instead of the dynare solution matrix `ghx`. So we recreate `T` here as this amounts to adding some zeros and focusing on selected variables only. * Added some checks to make sure the first-order approximation is selected. * Removed `kron_flag` as input, as `get_perturbation_params_derivs` looks into `options_.analytic_derivation_mode` for `kron_flag`. ## `dynare_identification.m` * make sure that setting `analytic_derivation_mode` is set both in `options_ident` and `options_`. Note that at the end of the function we restore the `options_` structure, so all changes are local. In a next merge request, I will remove the global variables to make all variables local. ## `get_identification_jacobians.m` * As `get_first_order_solution_params_derivs.m`is renamed to `get_perturbation_params_derivs.m`, the call is adapted. That is,`get_perturbation_params_derivs` does not compute the derivatives of the Kalman transition `A` and `B` matrix anymore, but instead of the dynare solution matrix `ghx` and `ghu`. So we recreate these matrices here instead of in `get_perturbation_params_derivs.m`. * Added `str2func` for better function handles in `fjaco.m`. ## `fjaco.m` * make `tol`an option, which can be adjusted by changing `options_.dynatol.x`for identification and parameter derivatives purposes. * include a check and an informative error message, if numerical derivatives (two-sided finite difference method) yield errors in `resol.m` for identification and parameter derivatives purposes. This closes issue Dynare/dynare#1595. * Changed year of copyright to 2010-2017,2019 *** # Further suggestions and questions * Ones this is merged, I will merge request an improvement of the identification toolbox, which will work up to third order using the pruned state space. This will also remove some issues and bugs, and also I will remove global variables in this request. * The third-order derivatives can be further improved by taking sparsity into account and use mex versions for kronecker products etc. I leave this for further testing (and if anybody actually uses this ;-) )
2019-12-17 19:17:09 +01:00
2020-01-16 14:43:39 +01:00
% get some options for quick reference
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
iload = options_ident.load_ident_files;
SampleSize = options_ident.prior_mc;
2017-05-16 12:42:01 +02:00
if iload <=0
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%% Perform new identification analysis, i.e. do not load previous analysis
2017-05-16 12:42:01 +02:00
if prior_exist
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
% use information from estimated_params block
params = set_prior(estim_params_,M_,options_)';
if all(bayestopt_.pshape == 0)
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
% only bounds are specified in estimated_params
parameters = 'ML_Starting_value';
parameters_TeX = 'ML starting value';
2020-01-16 14:43:39 +01:00
fprintf('Testing ML Starting value\n');
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
% use user-defined option
switch parameters
2020-01-16 14:43:39 +01:00
case 'calibration'
parameters_TeX = 'Calibration';
fprintf('Testing calibration\n');
params(1,:) = get_all_parameters(estim_params_,M_);
case 'posterior_mode'
parameters_TeX = 'Posterior mode';
fprintf('Testing posterior mode\n');
params(1,:) = get_posterior_parameters('mode',M_,estim_params_,oo_,options_);
case 'posterior_mean'
parameters_TeX = 'Posterior mean';
fprintf('Testing posterior mean\n');
params(1,:) = get_posterior_parameters('mean',M_,estim_params_,oo_,options_);
case 'posterior_median'
parameters_TeX = 'Posterior median';
fprintf('Testing posterior median\n');
params(1,:) = get_posterior_parameters('median',M_,estim_params_,oo_,options_);
case 'prior_mode'
parameters_TeX = 'Prior mode';
fprintf('Testing prior mode\n');
params(1,:) = bayestopt_.p5(:);
case 'prior_mean'
parameters_TeX = 'Prior mean';
fprintf('Testing prior mean\n');
params(1,:) = bayestopt_.p1;
otherwise
fprintf('The option parameter_set has to be equal to: ''calibration'', ''posterior_mode'', ''posterior_mean'', ''posterior_median'', ''prior_mode'' or ''prior_mean''.\n');
error('IDENTIFICATION: The option ''parameter_set'' has an invalid value');
end
end
else
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% no estimated_params block is available, all stderr and model parameters, but no corr parameters are chosen
params = [sqrt(diag(M_.Sigma_e))', M_.params'];
parameters = 'Current_params';
parameters_TeX = 'Current parameter values';
2020-01-16 14:43:39 +01:00
fprintf('Testing all current stderr and model parameter values\n');
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
options_ident.tittxt = parameters; %title text for graphs and figures
% perform identification analysis for single point
2023-12-18 07:48:27 +01:00
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, ~, info, error_indicator_point] = ...
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables
2017-05-16 12:42:01 +02:00
if info(1)~=0
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 are errors in the solution algorithm
message = get_error_message(info,options_);
2020-01-16 14:43:39 +01:00
fprintf('-----------\n');
fprintf('The model does not solve for %s (info = %d: %s)\n', parameters, info(1), message);
fprintf('-----------\n');
if any(bayestopt_.pshape)
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 there are errors in the solution algorithm, try to sample a different point from the prior
2020-01-16 14:43:39 +01:00
fprintf('Try sampling up to 50 parameter sets from the prior.\n');
kk=0;
2017-05-16 12:42:01 +02:00
while kk<50 && info(1)
kk=kk+1;
params = Prior.draw();
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.tittxt = 'Random_prior_params'; %title text for graphs and figures
% perform identification analysis
2023-12-18 07:48:27 +01:00
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, ~, info, error_indicator_point] = ...
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
end
end
if info(1)
2020-01-16 14:43:39 +01:00
fprintf('\n-----------\n');
fprintf('Identification stopped:\n');
if any(bayestopt_.pshape)
2020-01-16 14:43:39 +01:00
fprintf('The model did not solve for any of 50 attempts of random samples from the prior\n');
end
2020-01-16 14:43:39 +01:00
fprintf('-----------\n');
return
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
% found a (random) point that solves the model
2020-01-16 14:43:39 +01:00
fprintf('Found a random draw from the priors that solves the model:\n');
disp(params);
fprintf('Identification now continues for this draw.');
parameters = 'Random_prior_params';
2016-05-31 11:42:24 +02:00
parameters_TeX = 'Random prior parameter draw';
end
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
ide_hess_point.params = params;
% save all output into identification folder
2020-01-16 14:43:39 +01:00
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_hess_point', 'ide_reducedform_point', 'ide_dynamic_point', 'store_options_ident');
save([IdentifDirectoryName '/' fname '_' parameters '_identif.mat'], 'ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_hess_point', 'ide_reducedform_point', 'ide_dynamic_point', 'store_options_ident');
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
% display results of identification analysis
identification.display(params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
if ~options_ident.no_identification_strength && ~options_.nograph && ~error_indicator_point.identification_strength && ~error_indicator_point.identification_moments
2020-01-16 14:43:39 +01:00
% plot (i) identification strength and sensitivity measure based on the moment information matrix and (ii) plot advanced analysis graphs
identification.plot(M_,params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, parameters_TeX, name_tex);
end
2017-05-16 12:42:01 +02:00
if SampleSize > 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
% initializations for Monte Carlo Analysis
2020-01-16 14:43:39 +01:00
fprintf('\nMonte Carlo Testing\n');
h = dyn_waitbar(0,'Monte Carlo identification checks ...');
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
iteration = 0; % initialize counter for admissable draws
run_index = 0; % initialize counter for admissable draws after saving previous draws to file(s)
2020-01-16 14:43:39 +01:00
file_index = 0; % initialize counter for files (if options_.MaxNumberOfBytes is reached, we store results in files)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_MC = options_ident; %store options structure for Monte Carlo analysis
options_MC.advanced = 0; %do not run advanced checking in a Monte Carlo analysis
options_ident.checks_via_subsets = 0; % for Monte Carlo analysis currently only identification.checks and not identification.checks_via_subsets is supported
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
iteration = 1; % iteration equals SampleSize and we are finished
2020-01-16 14:43:39 +01:00
pdraws = []; % to have output object otherwise map_ident.m may crash
end
2017-05-16 12:42:01 +02:00
while iteration < SampleSize
if external_sample
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
params = pdraws0(iteration+1,:); % loaded draws
else
params = Prior.draw(); % new random draw from prior
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
options_ident.tittxt = []; % clear title text for graphs and figures
% run identification analysis
2023-12-18 07:48:27 +01:00
[ide_moments, ide_spectrum, ide_minimal, ~, ide_reducedform, ide_dynamic, ~, info, error_indicator] = ...
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_MC, dataset_info, prior_exist, 0); % the 0 implies that we do not initialize persistent variables anymore
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 iteration==0 && info(1)==0 % preallocate storage in the first admissable run
delete([IdentifDirectoryName '/' fname '_identif_*.mat']) % delete previously saved results
2020-01-16 14:43:39 +01:00
MAX_RUNS_BEFORE_SAVE_TO_FILE = min(SampleSize,ceil(options_.MaxNumberOfBytes/(size(ide_reducedform.si_dREDUCEDFORM,1)*totparam_nbr)/8)); % set how many runs can be stored before we save to files
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
pdraws = zeros(SampleSize,totparam_nbr); % preallocate storage for draws in each row
2020-01-16 14:43:39 +01:00
% preallocate storage for dynamic model
STO_si_dDYNAMIC = zeros([size(ide_dynamic.si_dDYNAMIC, 1), modparam_nbr, MAX_RUNS_BEFORE_SAVE_TO_FILE]);
STO_DYNAMIC = zeros(size(ide_dynamic.DYNAMIC, 1), SampleSize);
IDE_DYNAMIC.ind_dDYNAMIC = ide_dynamic.ind_dDYNAMIC;
IDE_DYNAMIC.ino = zeros(SampleSize, modparam_nbr);
2020-01-16 14:43:39 +01:00
IDE_DYNAMIC.ind0 = zeros(SampleSize, modparam_nbr);
IDE_DYNAMIC.jweak = zeros(SampleSize, modparam_nbr);
IDE_DYNAMIC.jweak_pair = zeros(SampleSize, modparam_nbr*(modparam_nbr+1)/2);
IDE_DYNAMIC.cond = zeros(SampleSize, 1);
IDE_DYNAMIC.Mco = zeros(SampleSize, modparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% preallocate storage for reduced form
if ~options_MC.no_identification_reducedform
2020-01-16 14:43:39 +01:00
STO_si_dREDUCEDFORM = zeros([size(ide_reducedform.si_dREDUCEDFORM, 1), totparam_nbr, MAX_RUNS_BEFORE_SAVE_TO_FILE]);
STO_REDUCEDFORM = zeros(size(ide_reducedform.REDUCEDFORM, 1), SampleSize);
IDE_REDUCEDFORM.ind_dREDUCEDFORM = ide_reducedform.ind_dREDUCEDFORM;
IDE_REDUCEDFORM.ino = zeros(SampleSize, 1);
2020-01-16 14:43:39 +01:00
IDE_REDUCEDFORM.ind0 = zeros(SampleSize, totparam_nbr);
IDE_REDUCEDFORM.jweak = zeros(SampleSize, totparam_nbr);
IDE_REDUCEDFORM.jweak_pair = zeros(SampleSize, totparam_nbr*(totparam_nbr+1)/2);
IDE_REDUCEDFORM.cond = zeros(SampleSize, 1);
IDE_REDUCEDFORM.Mco = zeros(SampleSize, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
2020-01-16 14:43:39 +01:00
STO_si_dREDUCEDFORM = {};
STO_REDUCEDFORM = {};
IDE_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
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
% preallocate storage for moments
if ~options_MC.no_identification_moments && ~isempty(fieldnames(ide_moments))
2020-01-16 14:43:39 +01:00
STO_si_dMOMENTS = zeros([size(ide_moments.si_dMOMENTS, 1), totparam_nbr, MAX_RUNS_BEFORE_SAVE_TO_FILE]);
STO_MOMENTS = zeros(size(ide_moments.MOMENTS, 1), SampleSize);
IDE_MOMENTS.ind_dMOMENTS = ide_moments.ind_dMOMENTS;
IDE_MOMENTS.ino = zeros(SampleSize, 1);
2020-01-16 14:43:39 +01:00
IDE_MOMENTS.ind0 = zeros(SampleSize, totparam_nbr);
IDE_MOMENTS.jweak = zeros(SampleSize, totparam_nbr);
IDE_MOMENTS.jweak_pair = zeros(SampleSize, totparam_nbr*(totparam_nbr+1)/2);
IDE_MOMENTS.cond = zeros(SampleSize, 1);
IDE_MOMENTS.Mco = zeros(SampleSize, totparam_nbr);
IDE_MOMENTS.S = zeros(SampleSize, min(8, totparam_nbr));
IDE_MOMENTS.V = zeros(SampleSize, totparam_nbr, min(8, totparam_nbr));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
2020-01-16 14:43:39 +01:00
STO_si_dMOMENTS = {};
STO_MOMENTS = {};
IDE_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
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
% preallocate storage for spectrum
if ~options_MC.no_identification_spectrum && ~isempty(fieldnames(ide_spectrum))
2020-01-16 14:43:39 +01:00
STO_dSPECTRUM = zeros([size(ide_spectrum.dSPECTRUM, 1), size(ide_spectrum.dSPECTRUM, 2), MAX_RUNS_BEFORE_SAVE_TO_FILE]);
IDE_SPECTRUM.ind_dSPECTRUM = ide_spectrum.ind_dSPECTRUM;
IDE_SPECTRUM.ino = zeros(SampleSize, 1);
2020-01-16 14:43:39 +01:00
IDE_SPECTRUM.ind0 = zeros(SampleSize, totparam_nbr);
IDE_SPECTRUM.jweak = zeros(SampleSize, totparam_nbr);
IDE_SPECTRUM.jweak_pair = zeros(SampleSize, totparam_nbr*(totparam_nbr+1)/2);
IDE_SPECTRUM.cond = zeros(SampleSize, 1);
IDE_SPECTRUM.Mco = zeros(SampleSize, totparam_nbr);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
else
2020-01-16 14:43:39 +01:00
STO_dSPECTRUM = {};
IDE_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
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
% preallocate storage for minimal system
if ~options_MC.no_identification_minimal && ~isempty(fieldnames(ide_minimal)) && ide_minimal.minimal_state_space==1
2020-01-16 14:43:39 +01:00
STO_dMINIMAL = zeros([size(ide_minimal.dMINIMAL, 1), size(ide_minimal.dMINIMAL, 2), MAX_RUNS_BEFORE_SAVE_TO_FILE]);
IDE_MINIMAL.ind_dMINIMAL = ide_minimal.ind_dMINIMAL;
IDE_MINIMAL.ino = zeros(SampleSize, 1);
2020-01-16 14:43:39 +01:00
IDE_MINIMAL.ind0 = zeros(SampleSize, totparam_nbr);
IDE_MINIMAL.jweak = zeros(SampleSize, totparam_nbr);
IDE_MINIMAL.jweak_pair = zeros(SampleSize, totparam_nbr*(totparam_nbr+1)/2);
IDE_MINIMAL.cond = zeros(SampleSize, 1);
IDE_MINIMAL.Mco = zeros(SampleSize, totparam_nbr);
IDE_MINIMAL.minimal_state_space = zeros(SampleSize, 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
2020-01-16 14:43:39 +01:00
STO_dMINIMAL = {};
IDE_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
end
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
if info(1)==0 % if admissable draw
iteration = iteration + 1; %increase total index of admissable draws
run_index = run_index + 1; %increase index of admissable draws after saving to files
pdraws(iteration,:) = params; % store draw
% store results for steady state and dynamic model derivatives
STO_DYNAMIC(:,iteration) = ide_dynamic.DYNAMIC;
STO_si_dDYNAMIC(:,:,run_index) = ide_dynamic.si_dDYNAMIC;
IDE_DYNAMIC.cond(iteration,1) = ide_dynamic.cond;
IDE_DYNAMIC.ino(iteration,1) = ide_dynamic.ino;
IDE_DYNAMIC.ind0(iteration,:) = ide_dynamic.ind0;
IDE_DYNAMIC.jweak(iteration,:) = ide_dynamic.jweak;
IDE_DYNAMIC.jweak_pair(iteration,:) = ide_dynamic.jweak_pair;
IDE_DYNAMIC.Mco(iteration,:) = ide_dynamic.Mco;
2020-01-16 14:43:39 +01:00
% store results for reduced form
if ~options_MC.no_identification_reducedform && ~error_indicator.identification_reducedform
2020-01-16 14:43:39 +01:00
STO_REDUCEDFORM(:,iteration) = ide_reducedform.REDUCEDFORM;
STO_si_dREDUCEDFORM(:,:,run_index) = ide_reducedform.si_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
IDE_REDUCEDFORM.cond(iteration,1) = ide_reducedform.cond;
IDE_REDUCEDFORM.ino(iteration,1) = ide_reducedform.ino;
IDE_REDUCEDFORM.ind0(iteration,:) = ide_reducedform.ind0;
IDE_REDUCEDFORM.jweak(iteration,:) = ide_reducedform.jweak;
IDE_REDUCEDFORM.jweak_pair(iteration,:) = ide_reducedform.jweak_pair;
IDE_REDUCEDFORM.Mco(iteration,:) = ide_reducedform.Mco;
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% store results for moments
if ~options_MC.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
STO_MOMENTS(:,iteration) = ide_moments.MOMENTS;
STO_si_dMOMENTS(:,:,run_index) = ide_moments.si_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
IDE_MOMENTS.cond(iteration,1) = ide_moments.cond;
IDE_MOMENTS.ino(iteration,1) = ide_moments.ino;
IDE_MOMENTS.ind0(iteration,:) = ide_moments.ind0;
IDE_MOMENTS.jweak(iteration,:) = ide_moments.jweak;
IDE_MOMENTS.jweak_pair(iteration,:) = ide_moments.jweak_pair;
IDE_MOMENTS.Mco(iteration,:) = ide_moments.Mco;
IDE_MOMENTS.S(iteration,:) = ide_moments.S;
IDE_MOMENTS.V(iteration,:,:) = ide_moments.V;
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
% store results for spectrum
if ~options_MC.no_identification_spectrum && ~error_indicator.identification_spectrum
STO_dSPECTRUM(:,:,run_index) = ide_spectrum.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
IDE_SPECTRUM.cond(iteration,1) = ide_spectrum.cond;
IDE_SPECTRUM.ino(iteration,1) = ide_spectrum.ino;
IDE_SPECTRUM.ind0(iteration,:) = ide_spectrum.ind0;
IDE_SPECTRUM.jweak(iteration,:) = ide_spectrum.jweak;
IDE_SPECTRUM.jweak_pair(iteration,:) = ide_spectrum.jweak_pair;
IDE_SPECTRUM.Mco(iteration,:) = ide_spectrum.Mco;
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
% store results for minimal system
if ~options_MC.no_identification_minimal
if ~error_indicator.identification_minimal
STO_dMINIMAL(:,:,run_index) = ide_minimal.dMINIMAL;
IDE_MINIMAL.cond(iteration,1) = ide_minimal.cond;
IDE_MINIMAL.ino(iteration,1) = ide_minimal.ino;
IDE_MINIMAL.ind0(iteration,:) = ide_minimal.ind0;
IDE_MINIMAL.jweak(iteration,:) = ide_minimal.jweak;
IDE_MINIMAL.jweak_pair(iteration,:) = ide_minimal.jweak_pair;
IDE_MINIMAL.Mco(iteration,:) = ide_minimal.Mco;
IDE_MINIMAL.minimal_state_space(iteration,:) = ide_minimal.minimal_state_space;
else
IDE_MINIMAL.minimal_state_space(iteration,:) = ide_minimal.minimal_state_space;
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
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
% save results to file: either to avoid running into memory issues, i.e. (run_index==MAX_RUNS_BEFORE_SAVE_TO_FILE) or if finished (iteration==SampleSize)
if run_index==MAX_RUNS_BEFORE_SAVE_TO_FILE || iteration==SampleSize
file_index = file_index + 1;
2020-01-16 14:43:39 +01:00
if run_index < MAX_RUNS_BEFORE_SAVE_TO_FILE
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
%we are finished (iteration == SampleSize), so get rid of additional storage
STO_si_dDYNAMIC = STO_si_dDYNAMIC(:,:,1:run_index);
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 ~options_MC.no_identification_reducedform
STO_si_dREDUCEDFORM = STO_si_dREDUCEDFORM(:,:,1:run_index);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_moments
STO_si_dMOMENTS = STO_si_dMOMENTS(:,:,1:run_index);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_spectrum
STO_dSPECTRUM = STO_dSPECTRUM(:,:,1:run_index);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_minimal
STO_dMINIMAL = STO_dMINIMAL(:,:,1:run_index);
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
save([IdentifDirectoryName '/' fname '_identif_' int2str(file_index) '.mat'], 'STO_si_dDYNAMIC');
STO_si_dDYNAMIC = zeros(size(STO_si_dDYNAMIC)); % reset storage
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 ~options_MC.no_identification_reducedform
save([IdentifDirectoryName '/' fname '_identif_' int2str(file_index) '.mat'], 'STO_si_dREDUCEDFORM', '-append');
STO_si_dREDUCEDFORM = zeros(size(STO_si_dREDUCEDFORM)); % reset storage
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
if ~options_MC.no_identification_moments
save([IdentifDirectoryName '/' fname '_identif_' int2str(file_index) '.mat'], 'STO_si_dMOMENTS','-append');
STO_si_dMOMENTS = zeros(size(STO_si_dMOMENTS)); % reset storage
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_spectrum
save([IdentifDirectoryName '/' fname '_identif_' int2str(file_index) '.mat'], 'STO_dSPECTRUM','-append');
STO_dSPECTRUM = zeros(size(STO_dSPECTRUM)); % reset storage
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_minimal
save([IdentifDirectoryName '/' fname '_identif_' int2str(file_index) '.mat'], 'STO_dMINIMAL','-append');
STO_dMINIMAL = zeros(size(STO_dMINIMAL)); % reset storage
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
run_index = 0; % reset index
end
if SampleSize > 1 && mod(iteration,3)
2020-01-16 14:43:39 +01:00
dyn_waitbar(iteration/SampleSize, h, ['MC identification checks ', int2str(iteration), '/', int2str(SampleSize)]);
end
end
end
2017-05-16 15:10:20 +02:00
2017-05-16 12:42:01 +02:00
if SampleSize > 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
dyn_waitbar_close(h);
normalize_STO_DYNAMIC = std(STO_DYNAMIC,0,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
if ~options_MC.no_identification_reducedform
normalize_STO_REDUCEDFORM = std(STO_REDUCEDFORM,0,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
end
if ~options_MC.no_identification_moments
normalize_STO_MOMENTS = std(STO_MOMENTS,0,2);
end
if ~options_MC.no_identification_minimal
2020-01-16 14:43:39 +01:00
normalize_STO_MINIMAL = 1; %not used (yet)
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_spectrum
2020-01-16 14:43:39 +01:00
normalize_STO_SPECTRUM = 1; %not used (yet)
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
normaliz1 = std(pdraws);
iter = 0;
2017-05-16 12:42:01 +02:00
for ifile_index = 1:file_index
load([IdentifDirectoryName '/' fname '_identif_' int2str(ifile_index) '.mat'], 'STO_si_dDYNAMIC');
maxrun_dDYNAMIC = size(STO_si_dDYNAMIC,3);
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 ~options_MC.no_identification_reducedform
load([IdentifDirectoryName '/' fname '_identif_' int2str(ifile_index) '.mat'], 'STO_si_dREDUCEDFORM');
maxrun_dREDUCEDFORM = size(STO_si_dREDUCEDFORM,3);
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
maxrun_dREDUCEDFORM = 0;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_moments
load([IdentifDirectoryName '/' fname '_identif_' int2str(ifile_index) '.mat'], 'STO_si_dMOMENTS');
maxrun_dMOMENTS = size(STO_si_dMOMENTS,3);
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
maxrun_dMOMENTS = 0;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_spectrum
load([IdentifDirectoryName '/' fname '_identif_' int2str(ifile_index) '.mat'], 'STO_dSPECTRUM');
maxrun_dSPECTRUM = size(STO_dSPECTRUM,3);
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
maxrun_dSPECTRUM = 0;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_minimal
load([IdentifDirectoryName '/' fname '_identif_' int2str(ifile_index) '.mat'], 'STO_dMINIMAL');
maxrun_dMINIMAL = size(STO_dMINIMAL,3);
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
maxrun_dMINIMAL = 0;
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
2023-11-30 12:26:58 +01:00
si_dDYNAMICnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_si_dDYNAMIC,2));
if ~options_MC.no_identification_reducedform
si_dREDUCEDFORMnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_si_dREDUCEDFORM,2));
end
if ~options_MC.no_identification_moments
si_dMOMENTSnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_si_dMOMENTS,2));
end
if ~options_MC.no_identification_spectrum
dSPECTRUMnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_dSPECTRUM,2));
end
if ~options_MC.no_identification_minimal
dMINIMALnorm=NaN(max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL]),size(STO_dMINIMAL,2));
end
for irun=1:max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL])
iter=iter+1;
% note that this is not the same si_dDYNAMICnorm as computed in identification.analysis
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
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
si_dDYNAMICnorm(iter,:) = identification.vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end);
if ~options_MC.no_identification_reducedform && ~isempty(STO_si_dREDUCEDFORM)
% note that this is not the same si_dREDUCEDFORMnorm as computed in identification.analysis
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
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
si_dREDUCEDFORMnorm(iter,:) = identification.vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_moments && ~isempty(STO_si_dMOMENTS)
% note that this is not the same si_dMOMENTSnorm as computed in identification.analysis
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
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
si_dMOMENTSnorm(iter,:) = identification.vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1;
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_spectrum && ~isempty(STO_dSPECTRUM)
% note that this is not the same dSPECTRUMnorm as computed in identification.analysis
dSPECTRUMnorm(iter,:) = identification.vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_minimal && ~isempty(STO_dMINIMAL)
% note that this is not the same dMINIMALnorm as computed in identification.analysis
dMINIMALnorm(iter,:) = identification.vnorm(STO_dMINIMAL(:,:,irun)); %not yet used
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
IDE_DYNAMIC.si_dDYNAMICnorm = si_dDYNAMICnorm;
save([IdentifDirectoryName '/' fname '_identif.mat'], 'pdraws', 'IDE_DYNAMIC','STO_DYNAMIC','-append');
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 ~options_MC.no_identification_reducedform
IDE_REDUCEDFORM.si_dREDUCEDFORMnorm = si_dREDUCEDFORMnorm;
save([IdentifDirectoryName '/' fname '_identif.mat'], 'IDE_REDUCEDFORM', 'STO_REDUCEDFORM','-append');
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_MC.no_identification_moments
IDE_MOMENTS.si_dMOMENTSnorm = si_dMOMENTSnorm;
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
save([IdentifDirectoryName '/' fname '_identif.mat'], 'IDE_MOMENTS', 'STO_MOMENTS','-append');
end
end
2017-05-16 15:10:20 +02:00
else
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%% load previous analysis
load([IdentifDirectoryName '/' fname '_identif']);
parameters = store_options_ident.parameter_set;
options_ident.parameter_set = 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
options_ident.prior_mc = size(pdraws,1);
SampleSize = options_ident.prior_mc;
options_.options_ident = options_ident;
2017-05-16 15:10:20 +02:00
end
%% if identification.run is called as it own function (not through identification command) and if we load files
2017-05-16 12:42:01 +02:00
if nargout>3 && iload
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
filnam = dir([IdentifDirectoryName '/' fname '_identif_*.mat']);
2020-01-16 14:43:39 +01:00
STO_si_dDYNAMIC = [];
STO_si_dREDUCEDFORM = [];
STO_si_dMOMENTS = [];
STO_dSPECTRUM = [];
STO_dMINIMAL = [];
2017-05-16 12:42:01 +02:00
for j=1:length(filnam)
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
load([IdentifDirectoryName '/' fname '_identif_',int2str(j),'.mat']);
STO_si_dDYNAMIC = cat(3,STO_si_dDYNAMIC, STO_si_dDYNAMIC(:,abs(iload),:));
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 ~options_ident.no_identification_reducedform
STO_si_dREDUCEDFORM = cat(3,STO_si_dREDUCEDFORM, STO_si_dREDUCEDFORM(:,abs(iload),:));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_moments
STO_si_dMOMENTS = cat(3,STO_si_dMOMENTS, STO_si_dMOMENTS(:,abs(iload),:));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_spectrum
STO_dSPECTRUM = cat(3,STO_dSPECTRUM, STO_dSPECTRUM(:,abs(iload),:));
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
end
if ~options_ident.no_identification_minimal
STO_dMINIMAL = cat(3,STO_dMINIMAL, STO_dMINIMAL(:,abs(iload),:));
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
2017-05-16 12:42:01 +02:00
if iload
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 previous analysis is loaded
2020-01-16 14:43:39 +01:00
fprintf(['Testing %s\n',parameters]);
identification.display(ide_hess_point.params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
if ~options_.nograph && ~error_indicator_point.identification_strength && ~error_indicator_point.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
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
identification.plot(M_,ide_hess_point.params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, [], name_tex);
end
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
%displaying and plotting of results for MC sample
if SampleSize > 1
2020-01-16 14:43:39 +01:00
fprintf('\nTesting MC sample\n');
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
%print results to console but make sure advanced=0
advanced0 = options_ident.advanced;
options_ident.advanced = 0;
identification.display(pdraws, IDE_REDUCEDFORM, IDE_MOMENTS, IDE_SPECTRUM, IDE_MINIMAL, name, options_ident);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.advanced = advanced0; % reset advanced setting
if ~options_.nograph && isfield(ide_hess_point,'ide_strength_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
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
identification.plot(M_, pdraws, IDE_MOMENTS, ide_hess_point, IDE_REDUCEDFORM, IDE_DYNAMIC, options_ident.advanced, 'MC sample ', name, ...
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, [], name_tex);
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
%advanced display and plots for MC Sample, i.e. look at draws with highest/lowest condition number
if options_ident.advanced
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
jcrit = find(IDE_MOMENTS.ino);
if length(jcrit) < SampleSize
2017-05-16 12:42:01 +02:00
if isempty(jcrit)
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
% Make sure there is no overflow of plots produced (these are saved to the disk anyways)
store_nodisplay = options_.nodisplay;
options_.nodisplay = 1;
% HIGHEST CONDITION NUMBER
[~, jmax] = max(IDE_MOMENTS.cond);
tittxt = 'Draw with HIGHEST condition number';
2020-01-16 14:43:39 +01:00
fprintf('\nTesting %s.\n',tittxt);
2017-05-16 12:42:01 +02:00
if ~iload
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.tittxt = tittxt; %title text for graphs and figures
2023-12-18 07:48:27 +01:00
[ide_moments_max, ide_spectrum_max, ide_minimal_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, ~, ~, error_indicator_max] = ...
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmax,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes some persistent variables
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_max', 'ide_moments_max', 'ide_spectrum_max', 'ide_minimal_max','ide_reducedform_max', 'ide_dynamic_max', 'jmax', '-append');
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
advanced0 = options_ident.advanced; options_ident.advanced = 1; % make sure advanced setting is on
identification.display(pdraws(jmax,:), ide_reducedform_max, ide_moments_max, ide_spectrum_max, ide_minimal_max, name, options_ident);
options_ident.advanced = advanced0; %reset advanced setting
if ~options_.nograph && ~error_indicator_max.identification_strength && ~error_indicator_max.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
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
identification.plot(M_, pdraws(jmax,:), ide_moments_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, 1, tittxt, name, ...
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt, name_tex);
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
% SMALLEST condition number
[~, jmin] = min(IDE_MOMENTS.cond);
tittxt = 'Draw with SMALLEST condition number';
2020-01-16 14:43:39 +01:00
fprintf('Testing %s.\n',tittxt);
2017-05-16 12:42:01 +02:00
if ~iload
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.tittxt = tittxt; %title text for graphs and figures
2023-11-30 12:26:58 +01:00
[ide_moments_min, ide_spectrum_min, ide_minimal_min, ide_hess_min, ide_reducedform_min, ide_dynamic_min, ~, ~, error_indicator_min] = ...
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmin,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes persistent variables
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_min', 'ide_moments_min','ide_spectrum_min','ide_minimal_min','ide_reducedform_min', 'ide_dynamic_min', 'jmin', '-append');
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
advanced0 = options_ident.advanced; options_ident.advanced = 1; % make sure advanced setting is on
identification.display(pdraws(jmin,:), ide_reducedform_min, ide_moments_min, ide_spectrum_min, ide_minimal_min, name, options_ident);
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.advanced = advanced0; %reset advanced setting
if ~options_.nograph && ~error_indicator_min.identification_strength && ~error_indicator_min.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
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
identification.plot(M_, pdraws(jmin,:),ide_moments_min,ide_hess_min,ide_reducedform_min,ide_dynamic_min,1,tittxt,name,...
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt,name_tex);
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% reset nodisplay option
options_.nodisplay = store_nodisplay;
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
% Make sure there is no overflow of plots produced (these are saved to the disk anyways)
store_nodisplay = options_.nodisplay;
options_.nodisplay = 1;
2017-05-16 12:42:01 +02:00
for j=1:length(jcrit)
2020-01-16 14:43:39 +01:00
tittxt = ['Rank deficient draw nr. ',int2str(j)];
fprintf('\nTesting %s.\n',tittxt);
2017-05-16 12:42:01 +02:00
if ~iload
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
options_ident.tittxt = tittxt; %title text for graphs and figures
[ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), derivatives_info_(j), info_resolve, error_indicator_j] = ...
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jcrit(j),:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
advanced0 = options_ident.advanced; options_ident.advanced = 1; %make sure advanced setting is on
identification.display(pdraws(jcrit(j),:), ide_reducedform_(j), ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), name, options_ident);
options_ident.advanced = advanced0; % reset advanced
if ~options_.nograph && ~error_indicator_j.identification_strength && ~error_indicator_j.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
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
identification.plot(M_, pdraws(jcrit(j),:), ide_moments_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), 1, tittxt, name, ...
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt, name_tex);
end
end
2017-05-16 12:42:01 +02:00
if ~iload
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_', 'ide_moments_', 'ide_reducedform_', 'ide_dynamic_', 'ide_spectrum_', 'ide_minimal_', 'jcrit', '-append');
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
% reset nodisplay option
options_.nodisplay = store_nodisplay;
end
end
end
end
Improvement of Identification Toolbox # Improvements * heavily commented (also auxiliary functions) and changed notation to make all the functions (hopefully) more readable and understandable, and hence, easier to debug * added identification criteria of Komunjer and Ng (2011, Econometrica) and Qu and Tkachenko (2012, Quantitative Economics) * tests can be turned of, i.e. nostrength disables identification strenght, noreducedform disables reduced form criteria, nomoments disables moment criteria, nospectrum disables spectrum criteria, nominimal disables minimal system criteria * all kronflags (analytic_derivation_mode) actually work in all functions * added functionality when there is correlation in Sigma_e and when one wants to consider corr parameters of exogenous shocks. Previously, (1) corr parameters were not allowed when calling identification and (2) when Sigma_e was not diagonal then the toolbox relied on numerical derviatives only (kronflag=-1). Now it is possible to handle both identification of corr parameters as well as correct analytical derivatives when Sigma_e is not diagonal with all possible kronflag values (-1|-2|0|1) * all plots and results are stored in the same folder named identification (previously there was another one with a capital I (Identification)) # Needed changes to preprocessor * add as field to options_ident: - tex (same as in options_) - nostrength (to turn off identification strength) - noreducedform (to turn off reduced form criteria) - nomoments (to turn off Iskrev's moment criteria) - nominimal (to turn off Komunjer and Ng's minimal system criteria) - nospectrum (to turn off Qu and Tkachenko's spectrum criteria) * add to options_ident: - normalize_jacobians (whether to normalize Jacobians or not) - grid_nbr (integer used to discretize the interval [-pi;pi] - tol_rank (tolerance level to compute ranks) - tol_deriv (tolerance level to select nonzero columns in derivatives) - tol_sv (tolerance level to select nonzero singular values) - ChecksViaSubsets (for debugging purposes, uses different function to find problematic parameter sets) - max_dim_subsets_groups (for debugging purposes, used for ChecksViaSubsets) # Further Suggestions * Rename getH.m into getParamsDerivReducedForm.m to make the purpose of this function evident * Rename getJJ.m into getIdentificationJacobians.m to make the purpose of this function evident * Rename thet2tau.m into IdentificationNumericalObjectiveFunction.m to make the purpose of this function evident * dYss, d2Yss, dg1 should also include derivatives wrt to stderr and corr parameters (even though these are just 0), as in other functions (getJJ, dynare_estimation) we always add these manually * I am pretty sure the current handling in getH.m of dYss and d2Yss is not correct in the case of nonstationary variables (if g2static is nonempty), I added a warning message, as I am not sure whether this is ever used * It would be straigthforward to also include stderr and corr parameters of measurement errors (these is not possible right now). Should I do this? * Computations of d2A and d2Om need to be checked, as the differences between computing these with analytically (kronflag=0|1) or numerically kronflag=-1|-2 is really large for the example model of AnSchorfheide. * I am not sure how to best normalize Qu and Tkachenko's G matrix. It looks (and in the Gaussian case actually is) very similar to the Ahess matrix. So I used the same normalization rule as for the Ahess matrix. See comments in identification_checks.m. Anyone has a better idea? Please also check the models in test/identification/cgg for differences. * parts that are unclear to me are marked by a [@wmutschl] tag * the run time of tests/identification/as2007.mod increases from 0h01m27s to 0h03m46s (as Qu and Tkachenko's G matrix takes a little while to compute). One could decrease prior_mc=250 to prior_mc=150. # New functions * commutation: Returns Magnus and Neudecker's commutation matrix that solves k*vec(X)=vec(X') * DerivABCD: Derivative of X(p)=A(p)*B(p)*C(p)*D(p) w.r.t to p as in Magnus and Neudecker (1999), p. 175 * DeriveMinimalState: Derives minimal state space system by checking observability and controllability of all possible combinations of variables * duplication: Duplication Matrix (and its Moore Penrose Inverse) as defined by Magnus and Neudecker (2002), p.49, Dp*vec(X) = X * identification_checks_via_subsets: finds problematic parameters in a bruteforce fashion: It computes the rank of the Jacobians for all possible parameter combinations, if the rank condition is not fullfilled, these parameter sets are flagged as non-identifiable. For debugging purposes only, as the current identification_checks.m (based on nullspace and multicorrelation coefficients) is much faster # Detailed changes in getH.m * functionality improvements - heavily commented (also auxiliary functions) and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - fixed function for all values of kronflag, i.e. kronflag=-2|-1|0|1. Previosuly, only kronflag=-2|0 were working, all other kronflags ran into errors (-1 was actually never called , but was dealt with in getJJ.m). I assume kronflag=-1|1 was used only for debugging issues, but still was not working. I fixed this now, the function now works out-of-the-box for all kronflag values. - I also outlined and documented what each kronflag does and point to the corresponding equations in Ratto and Iskrev (2012) or Iskrev (2010,Appendix A) - the function additionally outputs the Jacobians of B and Sig, which are needed for Qu and Tkachenko (2012) and Komunjer and Ng (2011)'s criteria - Moved computation of Jacobian of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into getJJ.m to have all Jacobians which are needed for identification in one place. That is, getH.m computes first and second parameter derivatives of (1) reduced-form solution, (2) steady state and (3) Jacobian of dynamic model, whereas getJJ computes and sets up all Jacobians which are used for identification purposes. Therefore, getH might be useful more generally for other purposes than identification. For instance, when doing a GMM estimation, we could use this function to compute analytically the gradient of the moments and provide this to the optimizer used in a GMM context. * output arguments - renamed `H` (Jacobian wrt parameters of tau=[ys;vec(A);vech(B * M_.Sigma_e * B')] into dTAU, (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `Hss` (Jacobian of steady state wrt model parameters only) into `dYss` (as H is very confusing here, see above) - renamed `H2ss` (Hessian wrt model parameters only of ys) into d2Yss (as H is very confusing, see above) - renamed `gp` into `dg1`, where g1 corresponds to the same variable as in dynamic model files. Note that in params_deriv files gp lacks the contribution of Jacobian wrt steady state and dg1 includes this using the implicit function theorem as outlined in Ratto and Iskrev (2012). Hence, dg1 denotes Jacobian wrt to parameters. It is useful and important to distinguish gp and dg1. - added `dB` (Jacobian wrt parameters of solution matrix B) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) - added `dSig` (Jacobian wrt parameters of M_.Sigma_e) needed for Qu and Tkachenko (2012) as well as Komunjer and Ng (2011) * input arguments - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - renamed `iv` (index of variables to consider) into `indvar` - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - included `indpcorr` a matrix of indices for corr parameters to be checked * misc - distinguished clearly between variables in DR or in declaration order without overwriting this in between - added which functions call getH.m - updated copyright to 2010-2019 # Detailed changes in getJJ.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - added functionality when Sigma_e is not diagonal and/or when one wants to consider corr parameters of exogenous shocks independent of the value of kronflag - tidied the function up, such that it sets up all Jacobians which are needed for identification, i.e. Iskrev's J matrix, Qu and Tkachenko (2012)'s G matrix, Komunjer and Ng (2011)'s D matrix, reduced-form solution (dTAU), linear rational expectation (i.e. Jacobian of steady state and dynamic model equations dLRE). - dTAU is now constructed in getJJ instead of in getH (see comment above in getH.m) - works for all kronflags, i.e. for numerical derivatives (-1 and -2) as well as for analytical derivatives based on kronecker products (1) or Sylvester Equations (0) - added functionality for stderr and corr parameters independent of the value of kronflag (previously this was only possible with numerical derivatives, now it works for all kronflags) - finds minimal state vector needed for Komunjer and Ng (2011)'s criteria (function `DeriveMinimalState.m`) - moved computations from kronflag=-1 (which were used in case of corr in shock block) into getH.m, so that getJJ now only sets up the Jacobians for LRE, Iskrev's J, Qu and Tkachenko's G and Komunjer and Ng's D, whereas getH computes the Jacobians (wrt parameters) of A, B, Sigma_e, Om, Yss and g1. This should simplify debugging as everything is now in one place and not in two * output arguments - renamed `JJ` into `J` - renamed `H` into `dTAU` (as H is very confusing, e.g. in other functions it is a Hessian, or Hss and H2ss is also just the steady state. Morevoer, tau is used in Iskrev(2010) for the steady state and reduced-form solution) - renamed `gp` into `dLRE`, as this corresponds to Jacobian of LRE=[Yss;vec(g1)] where g1 is the Jacobian of the dynamic model equations. - renamed `gam` into `MOMENTS` - added `G` for Qu and Tkachenko's Jacobian matrix G - added `D` for Komunjer and Ng's Jacobian matrix D - reordered output arguments * input arguments - added `options_ident` as input argument; hence, `kronflag`, `nlags` and `useautocorr` are removed from input arguments as these are available in options_ident - Renamed `M_` to `M`, `estim_params_` to `estim_params`, `options_` to `options` , `oo_` to `oo` to visualize that these are local and not global variables - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - renamed `mf` (index of VAROBS variables) into `indvobs` * misc - updated copyright to 2010-2019 - provided some comments on several ways to compute the spectral density matrix - added which functions call getJJ.m # Detailed changes in thet2tau.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - Added output option to compute spectral density matrix - Reorded and added some output option. - Instead of Om, `outputflag=0` computes B and Sigma_e, which are needed for Qu and Tkachenko as well as Komunjer and Ng. The Jacobian of Om is then computed in getJJ or getH from Jacobian of B and Sigma_e. Due to some testing with An and Schorfheide model this seems to be more accurate when I compare these with the analytical derivatives. The old behavior (computing Om directly) can be restored by setting `outputflag=-2`. - In total this function can now be used to compute numerically Jacobians of Yss, A, B, Sigma_e, Om, g1, autocovariogram and spectral density - Clearly distinguished (and commented) on the different outputs of this function. - Works for all types of parameters, ie. model, stderr and corr. - This function can now also be used when there is no estimated_params block. Previously, there was an error when there was no estimated_params block when calling `set_all_parameters` as this requires some information in `estim_params`. I fixed this by providing a temporary local estim_parms structure with the necessary information on model, stderr and corr parameters. In this way, this can be easily extended to also include stderr and corr parameters of measurement errors. * output arguments - renamed `tau` into `out`, as this function computes *very* different things (and not only tau) depending on an input flag * input arguments - renamed `flagmoments` into `outputflag` as this function does not only compute moments but many other things (see above) - renamed `indx` (index of model parameters to be checked) into `indpmodel`, the p makes it more clear that this is a parameter index - renamed `indexo` (index of stderr parameters) into `indpstderr`, the p makes it more clear that this is a parameter index - added `indpcorr` (index of corr parameters) - merged `mf` (index of observable variables) and `iv` (index of variables to consider) into a single index `indvar` as there is no need to distinguish between these two indices (they were never used in combination) - added `grid_nbr` (number of grid points to compute spectral density) - reordered input arguments * misc - added which functions call thet2tau - updated copyright to 2010-2019 # Detailed changes in identification_analysis.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - renamed `dg1` to `dLRE`, renamed `vecg1` to `lre`, renamed `H` to `dTAU` (see comments above) - added option `numzerotolderiv` with default `1.e-8` used for non-zero derivatives - added option `numzerotolrank` with default `1.e-10` used for rank computations - added theoretical identification analysis based on Komunjer and Ng (2011)'s method, i.e. steady state and observational equivalent spectral densities within a minimal system - added theoretical identification analysis based on Qu and Tkachenko (2012)'s method, i.e. steady state and spectral density - restructured the code slightly to combined chunks of code that belong together on the one hand, and on the other hand to differentiate between the different criteria - added call to new function `identification_checks_via_subsets.m` (see above for the definition of the functionality) to perform identification checks differently as find it more intuitive and (most likely) more precise. * input arguments - removed `bounds` and `dataset_` as input argument, because these are not needed - moved `name_tex` and `tittxt` into `options_ident` as these two inputs are only used in `ident_bruteforce.m` and already set in `dynare_identification.m` * output arguments - added `ide_spectrum` structure for Qu and Tkachenko's criteria based on the spectral density - added `ide_minimal` structure for Komunjer and Ng's criteria based on the minimal state space system - reordered output arguments * misc - added which functions call identification_analysis - updated copyright to 2010-2019 # Detailed changes in dynare_identification.m * functionality improvements - heavily commented and changed notation of several variables to make this function (hopefully) more readable and understandable, and hence, easier to debug - included more options (and default values) which can be set by the user, i.e. nostrength, nomoments, nominimal, nospectrum, tex, tol_rank, tol_deriv, tol_sv, grid_nbr, ChecksViaSubsets, max_dim_subsets_group - instead of turning warnings globally off, I specified the relevant warnings for matlab and octave, respectively, off - improved the warning messages slightly - restructured chunks of code with respect to different criteria * output arguments - renamed arguments: TAU to STO_TAU, GAM to STO_MOMENTS, LRE to STO_LRE, gp to STO_si_dLRE, H to STO_si_dTAU, JJ to STO_si_J - added arguments: STO_G and STO_D for the two new criteria * misc - added which functions call dynare_identification - updated copyright to 2010-2019 # Detailed changes in identification_checks.m * functionality improvements - added checks for Komunjer and Ng's D matrix. Note that the Jacobian D=[D_par D_rest], where D_par depends on the parameters and D_rest does not. So this is taken into account. - added checks for Qu and Tkachenko's G matrix. Note that the Jacobian G is a Gram matrix with dimension nparam x nparam, similar to Ahess. So this is taken into account. I am, however, not sure whether this is correct regarding the multicorrelation and pairwise correlation coefficients. Please double check. - the rank is now actually computed at the prespecified tolerance level (and not Matlab's default level), so this is in accordance to the further analysis of problematic parameter sets * output arguments - added the rank to output arguments which is later also displayed - replaced the J or JJ part in the variable names with X as this function is used for all sorts of Jacobians, not only Iskrev's J * input arguments - renamed hess_flag to output_flag (and clearly outlined what each value does) - added tol_rank and tol_sv as input arguments, such that the tolerance levels can be changed by the user and not preimplemented in this function - added param_nbr which is needed for Komunjer and Ng's D matrix * misc - updated copyright to 2010-2019 # Detailed changes in ident_bruteforce.m * functionality improvements - the output directory was set with a capital I, i.e. Identification, whereas in all other functions we rely on lower case i, i.e. identification. I changed this to lower-cases, so everything is now saved in the same folder. - changed displayed strings to be more precise with the corresponding papers and notation * input arguments - renamed `n` to `max_dim_cova_group` to name options the same across functions - renamed `pnames_TeX` to `name_tex` to name options the same across functions - added `tol_deriv` as tolerance level which can be changed by the user * misc - Added some comments - updated copyright to 2010-2019 # Detailed changes in disp_identification.m * functionality improvements - this function displays the same output for different Jacobians, hence I put the common code into a for loop. This should simplify changing the output that is printed to the console. Previously the code was simply repeated for the different criteria and only the strings changed. - some settings relevant for the computation are now printed as a summary to the console - the tolerance level, rank and required rank are always displayed on the command line to see how many problematic sets there are and which tolerance level was used - the function is also able to display problematic parameters computed by the new function `identification_checks_via_subsets.m` which is only used for debugging. * input arguments - added `idespectrum` structure for analysis based on Qu and Tkachenko - added `ideminimal` structure for analysis based on Komunjer and Ng - added `options_ident` to have all necessary settings in a structure * misc - Added some comments - Removed uncommented code that was not used as this was redundant and probably an artifact of the original programming?! - updated copyright to 2010-2019 # Detailed changes in dsge_likelihood.m * misc - adjusted call of getH due to changes of input and output arguments - updated copyright to 2010-2019 # Detailed changes in cosn.m * misc - commented functionality, input and output arguments of this function - updated copyright to 2010-2019
2019-03-20 16:44:54 +01:00
%reset warning state
warning_config;
2023-12-18 07:48:27 +01:00
fprintf('\n==== Identification analysis completed ====\n\n')