Getting Posterior Mean of a parameter up until current iteration while fitting the model

42 views
Skip to first unread message

sepehr akhavan

unread,
Feb 29, 2016, 8:44:56 AM2/29/16
to Stan users mailing list
Hi,

I'm jointly fitting two models with stan. Consider \beta as a parameter that is sampled from model1 and is used as a covariate in model2 (model 1 and model 2 are both in one stan code - you may consider them as two separate likelihood functions). Is there any way in Stan that while I'm running the model and sampling parameters, I can get posterior mean of \beta parameter up until this current iteration of MCMC? 

Please note that this is not calculating posterior mean after running the stan code. This, in fact, is getting posterior mean of a parameter up until this current iteration of MCMC while I'm still running the stan code.

Thanks very much for your help,
-Sepehr


Ben Goodrich

unread,
Feb 29, 2016, 10:15:33 AM2/29/16
to Stan users mailing list
On Monday, February 29, 2016 at 8:44:56 AM UTC-5, sepehr akhavan wrote:
Please note that this is not calculating posterior mean after running the stan code. This, in fact, is getting posterior mean of a parameter up until this current iteration of MCMC while I'm still running the stan code.

Basically no. You can write the output to a CSV file and use a separate process to calculate the cumulative mean up to the last iteration written in the CSV file. You probably want to exclude the warmup period though.

Ben


Michael Betancourt

unread,
Feb 29, 2016, 3:49:17 PM2/29/16
to stan-...@googlegroups.com
Technically you can in CmdStan — because samples stream to 
the output CSV, running stansummary on an incomplete output
CSV will compute MCMC estimators up to that point.

--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bob Carpenter

unread,
Feb 29, 2016, 4:45:57 PM2/29/16
to stan-...@googlegroups.com
But you can't get it in the Stan code itself.
Stan doesn't allow any reflection into runtime
properties. That's on purpose --- we want the
Stan program to define a log density that doesn't
depend on any state (other than the data, of course).

- Bob
Reply all
Reply to author
Forward
0 new messages