Extract percentile values?

430 views
Skip to first unread message

Mahdi Akbarzadeh

unread,
May 25, 2016, 5:01:22 AM5/25/16
to Stan users mailing list
Hi all;
Suppose that we run a hypothetical simple model and the as you know the estimation output is as follow:

------------------------------------------------
> fit
Inference for Stan model: model.
1 chains, each with iter=10; warmup=5; thin=1; 
post-warmup draws per chain=5, total post-warmup draws=5.

      mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat
mu   -0.06    0.08 0.17 -0.27 -0.12 -0.12  0.11  0.12     5 0.76
lp__ -6.85    0.06 0.13 -7.00 -6.96 -6.87 -6.72 -6.72     5 0.76
-----------------------------------------------


How to extract the percentile value (for example 0.12) and save it to a vector for further work on it. 
Note that I want to replicate the model and save the values to a vector.

Best Regards
Mahdi

Ben Goodrich

unread,
May 25, 2016, 10:41:22 AM5/25/16
to Stan users mailing list
 
The print() method does not return anything, so I think your best bet would be

sapply(as.data.frame(fit), FUN = quantile, probs = 0.25)

Ben

Mahdi Akbarzadeh

unread,
May 25, 2016, 11:17:18 AM5/25/16
to stan-...@googlegroups.com
Thank you Ben.

--
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.



--


Sincerely,

Mahdi Akbarzadeh,

PhD Candidate in Biostatistics;

School of Public Health,

Department of Biostatistics and Epidemiology,


 

 
 

Michael Betancourt

unread,
May 26, 2016, 5:43:35 AM5/26/16
to stan-...@googlegroups.com
Note that these yield MCMC _estimates_ of the posterior quantiles,
not exact values.  In particular, quantiles below 5% and above 95%
are notoriously hard to estimate and the estimators will be really
noisy.

Mahdi Akbarzadeh

unread,
May 26, 2016, 9:28:54 AM5/26/16
to stan-...@googlegroups.com
These values are percentiles of the parameter posterior distribution. I use them as HPD intervals (0.025 and 0.0975).

Michael Betancourt

unread,
May 26, 2016, 9:35:56 AM5/26/16
to stan-...@googlegroups.com
No, they are empirical percentiles estimated from the MCMC
draws.  In particular, the 2.5% and 97.5% estimates are very
very noisy and we do not recommend using then to estimate
a HPD interval.  A 5%-95% interval is relatively robust but a
10%-90% is even better while still giving you a good idea of
the posterior concentration.

Tamas Papp

unread,
May 26, 2016, 9:42:04 AM5/26/16
to stan-...@googlegroups.com
There is a related (dormant?) issue about accessors which I opened a
while ago: https://github.com/stan-dev/rstan/issues/116

Mahdi Akbarzadeh

unread,
May 26, 2016, 10:25:30 AM5/26/16
to stan-...@googlegroups.com
Then what is the confidence coefficient for that? (5%-95%)?
Can you introduce a reference for the statement? 

Michael Betancourt

unread,
May 26, 2016, 10:37:36 AM5/26/16
to stan-...@googlegroups.com
Unfortunately there is little literature on the estimation of quantiles
from samples, but you see some of the issues in Andy’s paper,

The biggest challenge with these quantile estimators is that it’s
hard to assign confidence intervals because they’re not quite
expectations and hence don’t quite fall into MCMC central
limit theorems.  But if you don’t believe me then simulate it
yourself — start with IID gaussian draws and see how many
samples it takes to accurate pin down the extreme quantiles.

Bob Carpenter

unread,
May 26, 2016, 3:11:24 PM5/26/16
to stan-...@googlegroups.com
I think you guys may be talking past each other.

I think Mahdi's asking for how you assign confidence
to a parameter estimate, not how you calculate confidence
intervals for MCMC estimators of quantiles (though I
am interested in hearing more about the answer to that
question given that they're not expectations).

Mahdi --- those posterior intervals are Bayesian and any text
on Bayes should explain what's going on. They are not
highest posterior density intervals, just central ones. And
by all means do what Michael suggests in terms of pinning down
extreme quantiles. We should have that in a tutorial somewhere.

- Bob

Andrew Gelman

unread,
May 26, 2016, 4:12:34 PM5/26/16
to stan-...@googlegroups.com
If you really want to compute 95% interval from simulations more efficiently, we do have this:
http://www.stat.columbia.edu/~gelman/research/published/spin.pdf
But it seems so complicated that we haven't put it into Stan.
A

Krzysztof Sakrejda

unread,
May 26, 2016, 4:37:17 PM5/26/16
to Stan users mailing list
On Thursday, May 26, 2016 at 10:37:36 AM UTC-4, Michael Betancourt wrote:
limit theorems.  But if you don’t believe me then simulate it
yourself — start with IID gaussian draws and see how many
samples it takes to accurate pin down the extreme quantiles.


Or don't do it yourself but take a look at a very basic script here: 

K

 
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

Mahdi Akbarzadeh

unread,
May 28, 2016, 12:13:59 AM5/28/16
to stan-...@googlegroups.com
Hi all,
Thanks for your generous helps.I got useful information from messages you receive.
Krzysztof; I used the script for quantiles. thanks.

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.

--
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.

--
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.

--
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.

--
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.

--
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.
Reply all
Reply to author
Forward
0 new messages