From 8a09c61adb1c1899ed902647e09b9881c0e83c38 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Mon, 10 Aug 2015 18:43:49 +0200
Subject: [PATCH] Redefine oo_.posterior_std  and add oo_.posterior_std_at_mode

Makes clear that oo_.posterior_std_at_mode comes from mode-finding while oo_.posterior_std comes from MCMC
---
 doc/dynare.texi                           | 29 +++++++++++++++++++++--
 matlab/GetPosteriorParametersStatistics.m |  1 +
 matlab/convert_dyn_45_to_44.m             |  6 +++++
 matlab/display_estimation_results_table.m | 10 ++++----
 4 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index 6a553ff45e..000fa02424 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -5975,13 +5975,22 @@ Variable set by the @code{estimation} command, if it is used with
 @end defvr
 
 @defvr {MATLAB/Octave variable} oo_.posterior_mode
-Variable set by the @code{estimation} command, if it is used with
-@code{mh_replic > 0} or @code{load_mh_file} option. Fields are of the form:
+Variable set by the @code{estimation} command during mode-finding. Fields are 
+of the form:
 @example
 @code{oo_.posterior_mode.@var{ESTIMATED_OBJECT}.@var{VARIABLE_NAME}}
 @end example
 @end defvr
 
+@defvr {MATLAB/Octave variable} oo_.posterior_std_at_mode
+Variable set by the @code{estimation} command during mode-finding. It is based on the
+inverse Hessian at @code{oo_.posterior_mode}. Fields are 
+of the form:
+@example
+@code{oo_.posterior_std_at_mode.@var{ESTIMATED_OBJECT}.@var{VARIABLE_NAME}}
+@end example
+@end defvr
+
 @defvr {MATLAB/Octave variable} oo_.posterior_std
 Variable set by the @code{estimation} command, if it is used with
 @code{mh_replic > 0} or @code{load_mh_file} option. Fields are of the form:
@@ -5990,6 +5999,22 @@ Variable set by the @code{estimation} command, if it is used with
 @end example
 @end defvr
 
+@defvr {MATLAB/Octave variable} oo_.posterior_var
+Variable set by the @code{estimation} command, if it is used with
+@code{mh_replic > 0} or @code{load_mh_file} option. Fields are of the form:
+@example
+@code{oo_.posterior_var.@var{ESTIMATED_OBJECT}.@var{VARIABLE_NAME}}
+@end example
+@end defvr
+
+@defvr {MATLAB/Octave variable} oo_.posterior_median
+Variable set by the @code{estimation} command, if it is used with
+@code{mh_replic > 0} or @code{load_mh_file} option. Fields are of the form:
+@example
+@code{oo_.posterior_median.@var{ESTIMATED_OBJECT}.@var{VARIABLE_NAME}}
+@end example
+@end defvr
+
 Here are some examples of generated variables:
 
 @example
diff --git a/matlab/GetPosteriorParametersStatistics.m b/matlab/GetPosteriorParametersStatistics.m
index f674e071f8..84e9ee1a9e 100644
--- a/matlab/GetPosteriorParametersStatistics.m
+++ b/matlab/GetPosteriorParametersStatistics.m
@@ -382,6 +382,7 @@ eval(['oo.posterior_hpdinf.' type '.' name ' = hpdinterval(1);']);
 eval(['oo.posterior_hpdsup.' type '.' name ' = hpdinterval(2);']);      
 eval(['oo.posterior_median.' type '.' name ' = postmedian;']);
 eval(['oo.posterior_variance.' type '.' name ' = postvar;']);
+eval(['oo.posterior_std.' type '.' name ' = sqrt(postvar);']);
 eval(['oo.posterior_deciles.' type '.' name ' = postdecile;']);
 eval(['oo.posterior_density.' type '.' name ' = density;']);
 
diff --git a/matlab/convert_dyn_45_to_44.m b/matlab/convert_dyn_45_to_44.m
index ed1e704af7..392a7457ab 100644
--- a/matlab/convert_dyn_45_to_44.m
+++ b/matlab/convert_dyn_45_to_44.m
@@ -87,3 +87,9 @@ if isfield(oo_,'FilteredVariables')
         end
     end
 end
+
+%% set old field posterior_std and remove new field posterior_std_at_mode
+if isfield(oo_,'posterior_std_at_mode')
+    oo_.posterior_std=oo_.posterior_std_at_mode;
+    oo_=rmfield(oo_,'posterior_std_at_mode');
+end
diff --git a/matlab/display_estimation_results_table.m b/matlab/display_estimation_results_table.m
index 334182bcb3..d813d3f5ae 100644
--- a/matlab/display_estimation_results_table.m
+++ b/matlab/display_estimation_results_table.m
@@ -73,7 +73,7 @@ if np
                  header_width,name,xparam1(ip),stdh(ip),tstath(ip));
         end
         eval(['oo_.' field_name '_mode.parameters.' name ' = xparam1(ip);']);
-        eval(['oo_.' field_name '_std.parameters.' name ' = stdh(ip);']);
+        eval(['oo_.' field_name '_std_at_mode.parameters.' name ' = stdh(ip);']);
         ip = ip+1;
     end
     skipline()
@@ -95,7 +95,7 @@ if nvx
         end
         M_.Sigma_e(k,k) = xparam1(ip)*xparam1(ip);
         eval(['oo_.' field_name '_mode.shocks_std.' name ' = xparam1(ip);']);
-        eval(['oo_.' field_name '_std.shocks_std.' name ' = stdh(ip);']);
+        eval(['oo_.' field_name '_std_at_mode.shocks_std.' name ' = stdh(ip);']);
         ip = ip+1;
     end
     skipline()
@@ -116,7 +116,7 @@ if nvx
             fprintf('%-*s %8.4f %7.4f %7.4f \n',header_width,name,xparam1(ip),stdh(ip),tstath(ip))            
         end
         eval(['oo_.' field_name '_mode.measurement_errors_std.' name ' = xparam1(ip);']);
-        eval(['oo_.' field_name '_std.measurement_errors_std.' name ' = stdh(ip);']);
+        eval(['oo_.' field_name '_std_at_mode.measurement_errors_std.' name ' = stdh(ip);']);
         ip = ip+1;
     end
     skipline()
@@ -141,7 +141,7 @@ if ncx
         M_.Sigma_e(k1,k2) = xparam1(ip)*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
         M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
         eval(['oo_.' field_name '_mode.shocks_corr.' NAME ' = xparam1(ip);']);
-        eval(['oo_.' field_name '_std.shocks_corr.' NAME ' = stdh(ip);']);
+        eval(['oo_.' field_name '_std_at_mode.shocks_corr.' NAME ' = stdh(ip);']);
         ip = ip+1;
     end
     skipline()
@@ -164,7 +164,7 @@ if ncn
             fprintf('%-*s %8.4f %7.4f %7.4f \n',header_width,name,xparam1(ip),stdh(ip),tstath(ip));            
         end
         eval(['oo_.' field_name '_mode.measurement_errors_corr.' NAME ' = xparam1(ip);']);
-        eval(['oo_.' field_name '_std.measurement_errors_corr.' NAME ' = stdh(ip);']);
+        eval(['oo_.' field_name '_std_at_mode.measurement_errors_corr.' NAME ' = stdh(ip);']);
         ip = ip+1;
     end
     skipline()
-- 
GitLab