Forums

Back

Reading MCMC into R

MO
Megumi Oshima, modified 5 Years ago.

Reading MCMC into R

Youngling Posts: 9 Join Date: 5/14/19 Recent Posts

Hello,

I am using SS version 3.24 and am having trouble reading in the mcmc posteriors into r with r4ss. When I use SSgetMCMC I get an error that says "Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 1 did not have 707 elements"

The posteriors.sso and posterior_vectors.sso files (both attached) are not empty and after I ran the ss3 mceval it said the run completed. I attached a screenshot of the output. I saw in another post that there should be multiple mceval counters but mine stopped after mceval counter: 0 so I am worried something did not run correctly.  The thin interval is set at 100 and the burn interval is at 1000 in the starter file and I used -mcmc 50,000 and -mcsave 1,000 for the first run. Any advice would be appreciated. 

Cheers,

Meg 

 

 

IT
Ian Taylor, modified 5 Years ago.

RE: Reading MCMC into R

Youngling Posts: 117 Join Date: 12/8/14 Recent Posts
Hi Megumi,
I think there are a few things going on here.

First, the executable for SS version 3.24 wasn't properly deleting the posteriors.sso file before each new model run, so what you're seeing in that file is the result of 7 successive model runs, each of which wrote the MLE values to the the file with a new header. I think this has been fixed in SS version 3.30 so you would only get the single header line and single set of values.

Regardless of that issue, I think the main problem here is that the starter values settings are applied above and beyond the AMDB thinning interval applied at run time. 

The values you reported using
ss3 -mcmc 50000 and -mcsave 1000   
will save every 1000th sample from the 50,000 total, which will only be 50 sets of parameters that get saved.

Then when you run 
ss3 -mceval
the starter file setting to have a burn-in of 1000, will mean that you would need more than 1000 saved values before any get reported to the posteriors file (and only every 100th sample would be saved after that).

Running something like 
ss3 -mcmc 55000 and -mcsave 50
would produced 1100 saved parameter lines   
and then using the starter value settings of
100 # MCeval burn interval
1 # MCeval thin interval

would remove the first 100 saved samples (corresponding to the first 5000 of the original chain), and apply no thinning after that, leaving you with a total of 1000 rows in posteriors.sso.

Also, your screenshot of the DOS window output looks like what you would see after running
ss3 without either -mcmc or -mceval which should produce output like

MCMC: ...
MCMC finished; note: .sso and .ss_new files not produced after MCMC
and
MCeval: ...
MCMC finished; note: .sso and .ss_new files not produced after MCMC

Finally, the workflow for reading MCMC results into r4ss has changed, so now you can just provide the directory where the MCMC results are located (once you get it working) as the input "dir.mcmc" to the SS_output function rather than running SSgetMCMC. See ?SS_output and/or https://github.com/r4ss/r4ss/issues/257 for more detail.

Let me know if this helps or you have further problems.
-Ian


On Mon, Jun 17, 2019 at 9:05 AM Megumi Oshima <VLab.Notifications@noaa.gov> wrote:

Hello,

I am using SS version 3.24 and am having trouble reading in the mcmc posteriors into r with r4ss. When I use SSgetMCMC I get an error that says "Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 1 did not have 707 elements"

The posteriors.sso and posterior_vectors.sso files (both attached) are not empty and after I ran the ss3 mceval it said the run completed. I attached a screenshot of the output. I saw in another post that there should be multiple mceval counters but mine stopped after mceval counter: 0 so I am worried something did not run correctly.  The thin interval is set at 100 and the burn interval is at 1000 in the starter file and I used -mcmc 50,000 and -mcsave 1,000 for the first run. Any advice would be appreciated. 

Cheers,

Meg 

 

 


--
Megumi Oshima Stock Synthesis Virtual Lab Forum https://vlab.noaa.gov/group/stock-synthesis/discussions-forums-/-/message_boards/view_message/6874605 VLab.Notifications@noaa.gov
IT
Ian Taylor, modified 5 Years ago.

RE: Reading MCMC into R

Youngling Posts: 117 Join Date: 12/8/14 Recent Posts

Thanks to a comment from Max Cardinale, I see that an additional confusion was over the requirement that the "dir.mcmc" input to the SS_output function needed to be a relative path, not an absolute path. That has been changed in the development version of r4ss so either option should work. There will be an additional warning that was missing before when the specified path does not exist (as either absolute or relative).

MO
Megumi Oshima, modified 5 Years ago.

RE: Reading MCMC into R

Youngling Posts: 9 Join Date: 5/14/19 Recent Posts

Thanks Ian, that cleared things up. I was having problems with the dir.mcmc path but I got it figured out now. 

Thank you for your help.

Meg