From 4da95da54c0745c289bb5de15e271c1d88cca615 Mon Sep 17 00:00:00 2001 From: adjemian <adjemian@ac1d8469-bf42-47a9-8791-bf33cf982152> Date: Wed, 10 Sep 2008 15:40:31 +0000 Subject: [PATCH] =?UTF-8?q?v4.1:=20Posterior=20forecasts=20plots=20of=20bv?= =?UTF-8?q?ar=20=C3=A0=20la=20Sims=20report=20the=20median=20instead=20of?= =?UTF-8?q?=20the=20mean=20(because=20the=20median=20is=20less=20affected?= =?UTF-8?q?=20by=20=20the=20posterior=20draws=20such=20that=20the=20eigenv?= =?UTF-8?q?alues=20of=20the=20companion=20matrix=20are=20outside=20the=20u?= =?UTF-8?q?nit=20circle).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2057 ac1d8469-bf42-47a9-8791-bf33cf982152 --- doc/bvar-a-la-sims.tex | 4 ++-- matlab/bvar_forecast.m | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/doc/bvar-a-la-sims.tex b/doc/bvar-a-la-sims.tex index decbef20bb..50146e11f7 100644 --- a/doc/bvar-a-la-sims.tex +++ b/doc/bvar-a-la-sims.tex @@ -493,11 +493,11 @@ The \texttt{forecast} option is mandatory. The command will draw \texttt{bvar\_replic} random samples from the posterior distribution. For each draw, it will simulate one path without shocks, and one path with shocks. -\emph{Note:} during the random sampling process, every draw such that the associated companion matrix has eigenvalues outside the unit circle will be discarded. This is meant to avoid explosive time series, especially when using a distant prediction horizon. Since this behaviour induces a distortion of the prior distribution, a message will be displayed if draws are thus discarded, indicating how many have been (knowing that the number of accepted draws is equal to \texttt{bvar\_replic}). +% \emph{Note:} during the random sampling process, every draw such that the associated companion matrix has eigenvalues outside the unit circle will be discarded. This is meant to avoid explosive time series, especially when using a distant prediction horizon. Since this behaviour induces a distortion of the prior distribution, a message will be displayed if draws are thus discarded, indicating how many have been (knowing that the number of accepted draws is equal to \texttt{bvar\_replic}). The command will produce one graph per observed variable. Each graph displays: \begin{itemize} -\item a blue line for the mean forecast (equal to the mean of the simulated paths by linearity), +\item a blue line for the posterior median forecast,% (equal to the mean of the simulated paths by linearity), \item two green lines giving the confidence interval for the forecasts without shocks, \item two red lines giving the confidence interval for the forecasts with shocks. \end{itemize} diff --git a/matlab/bvar_forecast.m b/matlab/bvar_forecast.m index b2c655e440..edd75d63bc 100644 --- a/matlab/bvar_forecast.m +++ b/matlab/bvar_forecast.m @@ -36,7 +36,6 @@ function bvar_forecast(nlags) end [ny, nx, posterior, prior, forecast_data] = bvar_toolbox(nlags); - sims_no_shock = NaN(options_.forecast, ny, options_.bvar_replic); sims_with_shocks = NaN(options_.forecast, ny, options_.bvar_replic); @@ -53,7 +52,7 @@ function bvar_forecast(nlags) % Number of explosive VAR models sampled p = 0; - % Number of non-explosive VAR models sampled + % Loop counter initialization d = 0; while d <= options_.bvar_replic @@ -70,7 +69,6 @@ function bvar_forecast(nlags) test = (abs(eig(Companion_matrix))); if any(test>1.0000000000001) p = p+1; - continue end d = d+1; @@ -97,21 +95,22 @@ function bvar_forecast(nlags) end if p > 0 - disp('') + disp(' ') disp(['Some of the VAR models sampled from the posterior distribution']) - disp(['were found to be explosive (' int2str(p) ' samples).']) - disp('') + disp(['were found to be explosive (' num2str(p/options_.bvar_replic) ' percent).']) + disp(' ') end % Plot graphs sims_no_shock_mean = mean(sims_no_shock, 3); - - sort_idx = round((0.5 + [-options_.conf_sig, options_.conf_sig]/2) * options_.bvar_replic); + + sort_idx = round((0.5 + [-options_.conf_sig, options_.conf_sig, 0]/2) * options_.bvar_replic); sims_no_shock_sort = sort(sims_no_shock, 3); sims_no_shock_down_conf = sims_no_shock_sort(:, :, sort_idx(1)); sims_no_shock_up_conf = sims_no_shock_sort(:, :, sort_idx(2)); - + sims_no_shock_median = sims_no_shock_sort(:, :, sort_idx(3)); + sims_with_shocks_sort = sort(sims_with_shocks, 3); sims_with_shocks_down_conf = sims_with_shocks_sort(:, :, sort_idx(1)); sims_with_shocks_up_conf = sims_with_shocks_sort(:, :, sort_idx(2)); @@ -119,7 +118,7 @@ function bvar_forecast(nlags) dynare_graph_init(sprintf('BVAR forecasts (nlags = %d)', nlags), ny, {'b-' 'g-' 'g-' 'r-' 'r-'}); for i = 1:ny - dynare_graph([ sims_no_shock_mean(:, i) ... + dynare_graph([ sims_no_shock_median(:, i) ... sims_no_shock_up_conf(:, i) sims_no_shock_down_conf(:, i) ... sims_with_shocks_up_conf(:, i) sims_with_shocks_down_conf(:, i) ], ... options_.varobs(i, :)); @@ -172,7 +171,7 @@ function bvar_forecast(nlags) sims = squeeze(sims_no_shock(:,i,:)); eval(['oo_.bvar.forecast.no_shock.Mean.' name ' = sims_no_shock_mean(:,i);']); - eval(['oo_.bvar.forecast.no_shock.Median.' name ' = median(sims, 2);']); + eval(['oo_.bvar.forecast.no_shock.Median.' name ' = sims_no_shock_median(:,i);']); eval(['oo_.bvar.forecast.no_shock.Var.' name ' = var(sims, 0, 2);']); eval(['oo_.bvar.forecast.no_shock.HPDsup.' name ' = sims_no_shock_up_conf(:,i);']); eval(['oo_.bvar.forecast.no_shock.HPDinf.' name ' = sims_no_shock_down_conf(:,i);']); -- GitLab