Reshape error within McMCDiagnostics


I am trying to run a model using previous estimation results. But I get this error:

Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically
calculate the appropriate size for that dimension.

Error in McMCDiagnostics (line 94)
Draws = reshape(Draws, [NumberOfDraws nblck]);

The cause of the error seems to be that GetAllPosteriorDraws() in the previous line provides a 95832x1 array for Draws, even though NumberOfDraws=25000 and nblck=2.

Within GetAllPosteriorDraws(), I see this code:

Draws = zeros(NumberOfDraws*nblck,1);
if column>0
for blck = 1:nblck
for file = FirstMhFile:TotalNumberOfMhFile
load([DirectoryName ‘/’ M_.fname ‘_mh’ int2str(file) ‘_blck’ int2str(blck)],‘x2’)
NumberOfLines = size(x2(iline:end,:),1);
Draws(linee:linee+NumberOfLines-1) = x2(iline:end,column);
linee = linee+NumberOfLines;
iline = 1;

For each block, there are 24 mh files, with 50000 lines in total. The first file has 2084 lines. iline0 is set to 25001. So in the very first mh file, in the inner-most for loop, it skips every line in that mh file (because 25001>2084). But then, the for loop resets iline to 1, so in the second mh file, no lines are skipped. So instead of skipping 25000 of the 50000 lines for each block, in which case Draws would still have 50000 rows, the code only ends up skipping 2084 lines for each block. As a consequence, Draws is reset to have 95832 rows (i.e. 2*(50000-2084)).

I would appreciate any help on how to fix this error.

I can’t attach the full model and mh files because they’re too big. Here is the code, and the first mh files as a sample:
Domestic (790.2 KB)

To run the model, run multisector.mod, which itself calls run_model.mod (that’s where the estimation function is).


When running your code, I cannot reproduce the error, because there is no previous MCMC that can be loaded. Did you run the estimation yourself or are you trying to load an estimation run from someone else?

Sorry for the slow response. I am trying to load a previous estimation - I was not able to provide the full files in my original post because they’re too big. The full set of files is here: Supplementary Information for RDP 2018-04: DSGE Reno: Adding a Housing Block to a Small Open Economy Model | RBA.

I am trying to run multisector.mod (in the ‘Domestic Sector’ folder), which calls run_model.mod.