Hi
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);
iline0=iline;
if column>0
for blck = 1:nblck
iline=iline0;
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;
end
end
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 Sector.zip (790.2 KB)
To run the model, run multisector.mod, which itself calls run_model.mod (that’s where the estimation function is).
Thanks!