From f717712ed6810f52586fe190ac2b5d9c34b74cde Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Wed, 15 Jul 2020 14:34:04 +0200
Subject: [PATCH] Fix trace plots with measurement errors and their
 correlations

Problem was introduced when transitioning to cell arrays
---
 matlab/name2index.m                  | 4 ++--
 matlab/set_prior.m                   | 4 +---
 tests/measurement_errors/ls2003a.mod | 7 +++++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/matlab/name2index.m b/matlab/name2index.m
index 7645c11a29..3f75b5c8a0 100644
--- a/matlab/name2index.m
+++ b/matlab/name2index.m
@@ -87,7 +87,7 @@ end
 
 if strcmpi(type,'MeasurementError')
     if nargin<6% Covariance matrix diagonal term
-        i = nvx + strmatch(name1, M_.endo_names{estim_params_.var_endo(:,1)}, 'exact');
+        i = nvx + strmatch(name1, M_.endo_names(estim_params_.var_endo(:,1)), 'exact');
         if isempty(i)
             disp(['The standard deviation of the measurement error on ' name1  ' is not an estimated parameter!'])
             return
@@ -95,7 +95,7 @@ if strcmpi(type,'MeasurementError')
     else% Covariance matrix off-diagonal term
         offset = nvx+nvn+ncx;
         try
-            list_of_measurement_errors = { M_.endo_names{estim_params_.corrn(:,1)} , M_.endo_names{estim_params_.corrn(:,2)} };
+            list_of_measurement_errors = [M_.endo_names(estim_params_.corrn(:,1),1) , M_.endo_names(estim_params_.corrn(:,2),1)];
             k1 = strmatch(name1,list_of_measurement_errors(:,1),'exact');
             k2 = strmatch(name2,list_of_measurement_errors(:,2),'exact');
             i = offset+intersect(k1,k2);
diff --git a/matlab/set_prior.m b/matlab/set_prior.m
index a8a5c9e7e3..38a545661f 100644
--- a/matlab/set_prior.m
+++ b/matlab/set_prior.m
@@ -133,9 +133,7 @@ if ncn
     bayestopt_.p4 = [ bayestopt_.p4; estim_params_.corrn(:,10)]; %take generalized distribution into account
     bayestopt_.jscale = [ bayestopt_.jscale; estim_params_.corrn(:,11)];
     baseid = length(bayestopt_.name);
-    bayestopt_.name = [bayestopt_.name; cell(ncn, 1)]; [bayestopt_.name; cellstr([repmat('corr ',ncn,1) ...
-                        M_.endo_names{estim_params_.corrn(:,1)} ...
-                        repmat(', ',ncn,1) , M_.endo_names{estim_params_.corrn(:,2)}])];
+    bayestopt_.name = [bayestopt_.name; cell(ncn, 1)];;
     for i=1:ncn
         k1 = estim_params_.corrn(i,1);
         k2 = estim_params_.corrn(i,2);
diff --git a/tests/measurement_errors/ls2003a.mod b/tests/measurement_errors/ls2003a.mod
index 6d0cbee680..253900230e 100644
--- a/tests/measurement_errors/ls2003a.mod
+++ b/tests/measurement_errors/ls2003a.mod
@@ -61,7 +61,10 @@ stderr e_ys,inv_gamma_pdf,1.2533,0.6551;
 stderr e_pies,inv_gamma_pdf,1.88,0.9827;
 stderr dq,inv_gamma_pdf,0.001,0.0001;
 stderr de,inv_gamma_pdf,0.001,0.0001;
+stderr pie_obs,inv_gamma_pdf,0.001,0.0001;
+corr dq,de, normal_pdf,0,1;
+corr pie_obs,de, normal_pdf,0,1;
 end;
 
-estimation(datafile=data_ca1,first_obs=8,nobs=79,mh_nblocks=10,prefilter=1,mh_jscale=0.5,mh_replic=0,mode_check);
-
+estimation(datafile=data_ca1,first_obs=8,nobs=79,mh_nblocks=1,prefilter=1,mh_jscale=0.5,mh_replic=3000,mode_check);
+generate_trace_plots(1);
-- 
GitLab