From e94a698a9b51cc49821366c1002de996c3c8ff15 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer <jpfeifer@gmx.de> Date: Thu, 2 Jun 2016 14:52:10 +0200 Subject: [PATCH] Implement write_latex_prior_table.m Fixes and replaces write_table_prior.m and uses consistent name. Also includes documentation --- doc/dynare.texi | 10 +- matlab/write_latex_prior_table.m | 184 +++++++++++++++++++++++++++++++ matlab/write_table_prior.m | 142 ------------------------ tests/TeX/fs2000_corr_ME.mod | 2 + 4 files changed, 195 insertions(+), 143 deletions(-) create mode 100644 matlab/write_latex_prior_table.m delete mode 100644 matlab/write_table_prior.m diff --git a/doc/dynare.texi b/doc/dynare.texi index 9671a51e5d..55d8ea5b02 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -10064,7 +10064,15 @@ a table in a file named @code{<<M_.fname>>_latex_parameters.tex}. The command wr of the parameters currently stored. Thus, if parameters are set or changed in the steady state computation, the command should be called after a @code{steady}-command to make sure the parameters were correctly updated. The long names can be used to add parameter descriptions. Requires the -following @LaTeX{} packages: @code{longtable} +following @LaTeX{} packages: @code{longtable, booktabs} +@end deffn + +@deffn {MATLAB/Octave command} write_latex_prior_table ; + +Writes descriptive statistics about the prior distribution to +a @LaTeX{} table in a file named @code{<<M_.fname>>_latex_priors_table.tex}. The command writes the prior +definitions currently stored. Thus, the command must be invoked after a call to @code{estimation}. Requires the +following @LaTeX{} packages: @code{longtable, booktabs} @end deffn @deffn {MATLAB/Octave command} collect_LaTeX_Files (@code{M_}) ; diff --git a/matlab/write_latex_prior_table.m b/matlab/write_latex_prior_table.m new file mode 100644 index 0000000000..3b39c46a14 --- /dev/null +++ b/matlab/write_latex_prior_table.m @@ -0,0 +1,184 @@ +function write_latex_prior_table +%function write_latex_prior_table +% Writes a latex table with some descriptive statistics about the prior distribution. +% +% INPUTS +% none +% +% OUTPUTS +% none +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2015-16 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 <http://www.gnu.org/licenses/>. + +global M_ options_ bayestopt_ estim_params_ + +if ~any(bayestopt_.pshape > 0) + fprintf('\nwrite_latex_prior_table:: No prior distributions detected. Skipping table creation.\n') + return +end + +% get untruncated bounds +bounds = prior_bounds(bayestopt_, options_.prior_trunc); +lb=bounds.lb; +ub=bounds.ub; + +PriorNames = { 'Beta' , 'Gamma' , 'Gaussian' , 'Inv. Gamma' , 'Uniform' , 'Inv. Gamma -- 2', '', 'Weibull' }; + +fidTeX = fopen([M_.fname '_priors_table.tex'],'w+'); +fprintf(fidTeX,'%% TeX-table generated by Dynare write_latex_prior_table.m.\n'); +fprintf(fidTeX,'%% Prior Information\n'); +fprintf(fidTeX,['%% ' datestr(now,0)]); +fprintf(fidTeX,' \n'); +fprintf(fidTeX,' \n'); +fprintf(fidTeX,'\\begin{center}\n'); +fprintf(fidTeX,'\\begin{longtable}{lcccccccc} \n'); +fprintf(fidTeX,'\\caption{Prior information (parameters)}\\\\\n '); +fprintf(fidTeX,'\\label{Table:Prior}\\\\\n'); +fprintf(fidTeX, '\\toprule%%\n'); +if options_.prior_trunc==0 + fprintf(fidTeX,' & & & & & \\multicolumn{2}{c}{Bounds} & \\multicolumn{2}{c}{90\\%% HPDI} \\\\ \n'); +else + fprintf(fidTeX,' & & & & & \\multicolumn{2}{c}{Bounds*} & \\multicolumn{2}{c}{90\\%% HPDI} \\\\ \n'); +end +fprintf(fidTeX,' \\cmidrule(r{.75em}){6-7} \\cmidrule(r{.75em}){8-9}\n'); +fprintf(fidTeX,' & Distribution & Mean & Mode & Std.dev. & Lower & Upper & Lower & Upper \\\\ \n'); +fprintf(fidTeX, '\\midrule\n'); +fprintf(fidTeX, '\\endfirsthead\n'); +fprintf(fidTeX,'\\caption{(continued)}\\\\\n '); +fprintf(fidTeX, '\\toprule%%\n'); +if options_.prior_trunc==0 + fprintf(fidTeX,' & & & & & \\multicolumn{2}{c}{Bounds} & \\multicolumn{2}{c}{90\\%% HPDI} \\\\ \n'); +else + fprintf(fidTeX,' & & & & & \\multicolumn{2}{c}{Bounds*} & \\multicolumn{2}{c}{90\\%% HPDI} \\\\ \n'); +end +fprintf(fidTeX,' \\cmidrule(r{.75em}){6-7} \\cmidrule(r{.75em}){8-9}\n'); +fprintf(fidTeX,' & Distribution & Mean & Mode & Std.dev. & Lower & Upper & Lower & Upper \\\\ \n'); +fprintf(fidTeX,'\\midrule\n'); +fprintf(fidTeX,'\\endhead\n'); +if options_.prior_trunc~=0 + fprintf(fidTeX,'\\midrule\n'); + fprintf(fidTeX,sprintf('\\\\caption*{*Displayed bounds are after applying a prior truncation of options_.trunc=%4.3f}\\\\\\\\\n',options_.prior_trunc)); +end +fprintf(fidTeX,'\\midrule\n'); +fprintf(fidTeX,'\\multicolumn{9}{r}{(Continued on next page)} \\\\ \n'); +fprintf(fidTeX,'\\bottomrule\n'); +fprintf(fidTeX,'\\endfoot\n'); +if options_.prior_trunc~=0 + fprintf(fidTeX,'\\midrule\n'); + fprintf(fidTeX,sprintf('\\\\caption*{\\\\emph{Note:} Displayed bounds are after applying a prior truncation of options\\\\_.prior\\\\_trunc=%3.2e}\\\\\\\\\n',options_.prior_trunc)); +end +fprintf(fidTeX,'\\bottomrule\n'); +fprintf(fidTeX,'\\endlastfoot\n'); +% Column 1: a string for the name of the prior distribution. +% Column 2: the prior mean. +% Column 3: the prior mode. +% Column 4: the prior standard deviation. +% Column 5: the lower bound of the prior density support. +% Column 6: the upper bound of the prior density support. +% Column 7: the lower bound of the interval containing 90% of the prior mass. +% Column 8: the upper bound of the interval containing 90% of the prior mass. +PriorIntervals = prior_bounds(bayestopt_,(1-options_.prior_interval)/2) ; +for i=1:size(bayestopt_.name,1) + [tmp,TexName] = get_the_name(i,1,M_,estim_params_,options_); + PriorShape = PriorNames{ bayestopt_.pshape(i) }; + PriorMean = bayestopt_.p1(i); + PriorMode = bayestopt_.p5(i); + PriorStandardDeviation = bayestopt_.p2(i); + switch bayestopt_.pshape(i) + case { 1 , 5 } + LowerBound = bayestopt_.p3(i); + UpperBound = bayestopt_.p4(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + case { 2 , 4 , 6, 8 } + LowerBound = bayestopt_.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=ub(i); + else + UpperBound = '$\infty$'; + end + case 3 + if isinf(bayestopt_.p3(i)) && isinf(lb(i)) + LowerBound = '$-\infty$'; + else + LowerBound = bayestopt_.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + end + if isinf(bayestopt_.p4(i)) && isinf(ub(i)) + UpperBound = '$\infty$'; + else + UpperBound = bayestopt_.p4(i); + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + end + otherwise + error('write_latex_prior_table:: Dynare bug!') + end + format_string = build_format_string(PriorMode, PriorStandardDeviation,LowerBound,UpperBound); + fprintf(fidTeX,format_string, ... + TexName, ... + PriorShape, ... + PriorMean, ... + PriorMode, ... + PriorStandardDeviation, ... + LowerBound, ... + UpperBound, ... + PriorIntervals.lb(i), ... + PriorIntervals.ub(i) ); +end +fprintf(fidTeX,'\\end{longtable}\n '); +fprintf(fidTeX,'\\end{center}\n'); +fprintf(fidTeX,'%% End of TeX file.\n'); +fclose(fidTeX); + +function format_string = build_format_string(PriorMode,PriorStandardDeviation,LowerBound,UpperBound) +format_string = ['%s & %s & %6.4f &']; +if isnan(PriorMode) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(PriorStandardDeviation) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(LowerBound) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(UpperBound) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n']; \ No newline at end of file diff --git a/matlab/write_table_prior.m b/matlab/write_table_prior.m deleted file mode 100644 index 3c6c847c6a..0000000000 --- a/matlab/write_table_prior.m +++ /dev/null @@ -1,142 +0,0 @@ -function write_table_prior(lb, ub, DynareOptions, ModelInfo, BayesInfo, EstimationInfo) - -% This routine builds a latex table with some descriptive statistics about the prior distribution. - -% Copyright (C) 2015 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 <http://www.gnu.org/licenses/>. - -PriorNames = { 'Beta' , 'Gamma' , 'Gaussian' , 'Inverted Gamma' , 'Uniform' , 'Inverted Gamma -- 2' }; - -if size(ModelInfo.param_names,1)==size(ModelInfo.param_names_tex,1)% All the parameters have a TeX name. - fidTeX = fopen('priors_data.tex','w+'); - fprintf(fidTeX,'%% TeX-table generated by Dynare.\n'); - fprintf(fidTeX,'%% Prior Information\n'); - fprintf(fidTeX,['%% ' datestr(now,0)]); - fprintf(fidTeX,' \n'); - fprintf(fidTeX,' \n'); - fprintf(fidTeX,'\\begin{center}\n'); - fprintf(fidTeX,'\\begin{longtable}{l|cccccccc} \n'); - fprintf(fidTeX,'\\caption{Prior information (parameters)}\\\\\n '); - fprintf(fidTeX,'\\label{Table:Prior}\\\\\n'); - fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior mode & Prior s.d. & Lower Bound & Upper Bound & LB Untrunc. 80\\%% HPDI & UB Untrunc. 80\\%% HPDI \\\\ \n'); - fprintf(fidTeX,'\\hline \\endfirsthead \n'); - fprintf(fidTeX,'\\caption{(continued)}\\\\\n '); - fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior mode & Prior s.d. & Lower Bound & Upper Bound & LB Untrunc. 80\\%% HPDI & UB Untrunc. 80\\%% HPDI \\\\ \n'); - fprintf(fidTeX,'\\hline \\endhead \n'); - fprintf(fidTeX,'\\hline \\multicolumn{9}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); - fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); - % Column 1: a string for the name of the prior distribution. - % Column 2: the prior mean. - % Column 3: the prior mode. - % Column 4: the prior standard deviation. - % Column 5: the lower bound of the prior density support. - % Column 6: the upper bound of the prior density support. - % Column 7: the lower bound of the interval containing 80% of the prior mass. - % Column 8: the upper bound of the interval containing 80% of the prior mass. - prior_trunc_backup = DynareOptions.prior_trunc ; - DynareOptions.prior_trunc = (1-DynareOptions.prior_interval)/2 ; - PriorIntervals = prior_bounds(BayesInfo,DynareOptions) ; - DynareOptions.prior_trunc = prior_trunc_backup ; - for i=1:size(BayesInfo.name,1) - [tmp,TexName] = get_the_name(i,1,ModelInfo,EstimationInfo,DynareOptions); - PriorShape = PriorNames{ BayesInfo.pshape(i) }; - PriorMean = BayesInfo.p1(i); - PriorMode = BayesInfo.p5(i); - PriorStandardDeviation = BayesInfo.p2(i); - switch BayesInfo.pshape(i) - case { 1 , 5 } - LowerBound = BayesInfo.p3(i); - UpperBound = BayesInfo.p4(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - if ~isinf(ub(i)) - UpperBound=min(UpperBound,ub(i)); - end - case { 2 , 4 , 6 } - LowerBound = BayesInfo.p3(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - if ~isinf(ub(i)) - UpperBound=ub(i); - else - UpperBound = '$\infty$'; - end - case 3 - if isinf(BayesInfo.p3(i)) && isinf(lb(i)) - LowerBound = '$-\infty$'; - else - LowerBound = BayesInfo.p3(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - end - if isinf(BayesInfo.p4(i)) && isinf(ub(i)) - UpperBound = '$\infty$'; - else - UpperBound = BayesInfo.p4(i); - if ~isinf(ub(i)) - UpperBound=min(UpperBound,ub(i)); - end - end - otherwise - error('get_prior_info:: Dynare bug!') - end - format_string = build_format_string(PriorMode, PriorStandardDeviation,LowerBound,UpperBound); - fprintf(fidTeX,format_string, ... - TexName, ... - PriorShape, ... - PriorMean, ... - PriorMode, ... - PriorStandardDeviation, ... - LowerBound, ... - UpperBound, ... - PriorIntervals.lb(i), ... - PriorIntervals.ub(i) ); - end - fprintf(fidTeX,'\\end{longtable}\n '); - fprintf(fidTeX,'\\end{center}\n'); - fprintf(fidTeX,'%% End of TeX file.\n'); - fclose(fidTeX); -end - -function format_string = build_format_string(PriorMode,PriorStandardDeviation,LowerBound,UpperBound) -format_string = ['%s & %s & %6.4f &']; -if isnan(PriorMode) - format_string = [ format_string , ' %s &']; -else - format_string = [ format_string , ' %6.4f &']; -end -if ~isnumeric(PriorStandardDeviation) - format_string = [ format_string , ' %s &']; -else - format_string = [ format_string , ' %6.4f &']; -end -if ~isnumeric(LowerBound) - format_string = [ format_string , ' %s &']; -else - format_string = [ format_string , ' %6.4f &']; -end -if ~isnumeric(UpperBound) - format_string = [ format_string , ' %s &']; -else - format_string = [ format_string , ' %6.4f &']; -end -format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n']; \ No newline at end of file diff --git a/tests/TeX/fs2000_corr_ME.mod b/tests/TeX/fs2000_corr_ME.mod index 1be3270db9..6ac5cef60f 100644 --- a/tests/TeX/fs2000_corr_ME.mod +++ b/tests/TeX/fs2000_corr_ME.mod @@ -162,6 +162,8 @@ end; estimation(mode_compute=8,order=1,datafile='../fs2000/fsdat_simul',mode_check,smoother,filter_decomposition,mh_replic=4000, mh_nblocks=1, mh_jscale=0.8,forecast = 8,bayesian_irf,filtered_vars,filter_step_ahead=[1,3],irf=20,moments_varendo,contemporaneous_correlation,conditional_variance_decomposition=[1 2 4]) m P c e W R k d y; +write_latex_prior_table; + trace_plot(options_,M_,estim_params_,'PosteriorDensity',1); trace_plot(options_,M_,estim_params_,'StructuralShock',1,'eps_a') -- GitLab