Hi,
I am new to this group, so forgive me if this is the incorrect place to post this. I wanted to help by translating some existing examples in the aforementioned books (and maybe some others, for example some in Lee's book on 'Bayesian cognitive modelling') into working Stan code. I am newish to Stan; having used BUGS previously, but have been using it to successfully fit some hierarchical models that I previously struggled with, over the last couple of months. It may take me a bit longer than more experienced Stan developers to code some examples, but am hopeful I can contribute!
I am aware that there is already considerable effort to 'translate'/make working Stan code for the books I mentioned, and so wanted to ask - has work begun on writing Stan code for Gelman, Hill and other books? I can see that the majority of BUGS book examples are done already. Also, where would be most helpful for me to begin?
Hi Ben,This is a good place to start the discussion. We've started coding up models here:
https://github.com/stan-dev/example-models
Some of the models from Gelman and Hill have been implemented under the folder ARM.
More below.
On Sun, May 10, 2015 at 2:11 PM, Ben Lambert <ben.c....@googlemail.com> wrote:
Hi,
I am new to this group, so forgive me if this is the incorrect place to post this. I wanted to help by translating some existing examples in the aforementioned books (and maybe some others, for example some in Lee's book on 'Bayesian cognitive modelling') into working Stan code. I am newish to Stan; having used BUGS previously, but have been using it to successfully fit some hierarchical models that I previously struggled with, over the last couple of months. It may take me a bit longer than more experienced Stan developers to code some examples, but am hopeful I can contribute!
I'm sure you'll be contributing in short order!
I am aware that there is already considerable effort to 'translate'/make working Stan code for the books I mentioned, and so wanted to ask - has work begun on writing Stan code for Gelman, Hill and other books? I can see that the majority of BUGS book examples are done already. Also, where would be most helpful for me to begin?
Some background:
The example-models repository has just been a place where we have contributed models, without checking for quality. I'm sure not everything there even compiles under Stan. That said, some of them implementations might be the best way to do it. We just haven't systematically verified anything.Here are some things I think would be helpful:
* discuss how users would use the example-models repository and how we can make that experience better for them. I think one of the things we can do is to provide text descriptions about the models in a standard format.
* create a standard layout for each model; this should include the data and how to run the model
* consistent formatting, perhaps syntax highlighting in the description?
* apply best practices for model building
* place a little bit of process on the repository so everything that gets in meets the standards that we set
Daniel
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yes, this is how we should be rolling.
I added this to the notes.
- Bob
> On May 10, 2015, at 6:33 PM, Michael Betancourt <betan...@gmail.com> wrote:
>
<blockerSimulatedData.R><blockerUpdated.stan><blocker.data.R>
Firstly, divergences during warmup are ignorable as they usually typicallydenote poor steps in the adaptation instead of pathologies in the sampler.So if the divergences are really occurring only in the first 1000 iterationsthen you’re fine.
It’s only when you see divergences in the sampling phase that you haveto worry. In this case manually specifying a step size will not be sufficientbecause the adaptation will rapidly change the initial value (althoughsetting a lower step size can sometimes speed up adaptation if largerstep sizes lead to awkward parameter values and expensive likelihoodcomputations). What you have to do is increase the target acceptanceprobability (change “delta” parameter from the default 0.8 to 0.9 orhigher as necessary for removing the divergences).
For more see http://arxiv.org/abs/1312.0906.
On May 12, 2015, at 1:49 AM, Ben Lambert <ben.l...@some.ox.ac.uk> wrote:
<blockerSimulatedData.R><blockerUpdated.stan><blocker.data.R>
Great - thanks for that; much appreciated.
Firstly, divergences during warmup are ignorable as they usually typicallydenote poor steps in the adaptation instead of pathologies in the sampler.So if the divergences are really occurring only in the first 1000 iterationsthen you’re fine.
It’s only when you see divergences in the sampling phase that you haveto worry. In this case manually specifying a step size will not be sufficientbecause the adaptation will rapidly change the initial value (althoughsetting a lower step size can sometimes speed up adaptation if largerstep sizes lead to awkward parameter values and expensive likelihoodcomputations). What you have to do is increase the target acceptanceprobability (change “delta” parameter from the default 0.8 to 0.9 orhigher as necessary for removing the divergences).
For more see http://arxiv.org/abs/1312.0906.
On May 12, 2015, at 1:49 AM, Ben Lambert <ben.l...@some.ox.ac.uk> wrote:
<blockerSimulatedData.R><blockerUpdated.stan><blocker.data.R>
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks --- that looks awesome. Much more than we were
expecting. Although it'd be great, the key thing is getting
the code for both the BUGS model and "best practices" model right.
Your updated model looks great!
As to the direct translation, it's fine as is, but it doesn't have
to be literally line for line. I think it's OK to translate the model,
not the implementation. So it's OK to use, for example, binomial_logit
in the translation. This is really a judgment call, but I'd rather
err on the side of efficient Stan idioms as long as we literally
translate the model as written to one with the same posterior.
Maybe some bread crumbs in the text on the translation?
Then we want to provide the model we would've used.
Some specific comments:
* Num -> N
* keep the opening curly brace on the same line as the for statement
(we basically follow the Google code style in Stan as well as in
C++).
* spaces after commas (e.g., in gamma(0.001, 0.001))
> <Example1.pdf><blockerSimulatedData.R>
Thanks --- that looks fantastic. Are you generating the LaTeX
through knitr?
I like the plot with all the parameter values, but this style's going
to get problematic when the parameters aren't all on the same scale.
If I were doing it, I'd facet the different named parameters through
ggplot2. But this is already way more than we need in this context,
so I'm not suggesting redoing it!
In general, I think 90% intervals are OK --- the problem is that
the larger the interval, the noisier the endpoint estimates are.
It's great that you plotted that we get the same result as BUGS.
Could you indicate if it's OpenBUGS or WinBUGS and which version?
The overlplotting of orange and blue (great color choice, by the
way) in the BUGS vs. Stan is a bit hard to read, but I don't think
it's a big deal. What is an issue is that you probably want to be
comparing means +/- MCMC std error, as those are the things that should
converge to the same value if everything's working.
And to compare apples and apples, you need to do both with Stan's
method of computing n_eff. I have some code to convert R2jags
output to something Stan can process.
The bibliography's still messed up in terms of capitalization.
(And "2x 2" rather than "2 x 2".
You want to use "a---b" for em-dashes to separate text in
American English typesetting (you get an extra space in the UK,
but you also want to use the em-dash).
The values 1 and 0 shouldn't be quoted. A quote usually
indicates a character rather than the value.
Spaces, so it's not [0.025,0.975], but [0.025, 0.975].
> <Example1.pdf><Example1.tex>
First of all I want to say that this is really great! We need this type really bad and what you produced is really good stuff I think. Some comments:
1. I think it would be good to make the BUGS engine exchangeable, i.e. the user should be able to switch between WinBUGS (the mother of all BUGS), OpenBUGS and JAGS. There should be R packages out there which are of help here.
2. Before you move on to other examples I suggest to think about how all of the example can later on be processed in an automatic fashion, i.e. I am thinking of something similar (but more sophisticated) like the stan_demo function. Basically I would appreciate if one can get all these nice example models in a programmatic way as other people prefer different comparisons.
3. The way I once came up with to compare Stan vs WinBUGS output was the following:
- I declared WinBUGS as reference which is what you want to do as this type of work in anyway only for WinBUGS followers
- Then I standardize each quantity of interest from the models with respect to the median and robust standard deviation (inter-quantile-range divided by 1.34) such that the WinBUGS output and the Stan output becomes roughly standard normal
- Last, I computed the 2.5%, 5% ... 95%, 97.5% quantiles from each program and then checked that the absolute difference is below 0.1
4. The simulation of the fake data should be done somehow with the fixed_param algo from rstan as Bob points out.
Could we place this stuff in some git repo? This makes it easier to track the code & interact. My third point is something which really does not need to be part of this, but I would really appreciate if I could do this type of stuff with this work given that point 2 is taken care of.
Really cool!
Best,
Sebastian
On Tuesday, June 23, 2015 at 8:43:31 PM UTC+2, Bob Carpenter wrote:
> > On Jun 23, 2015, at 1:47 PM, Ben Lambert
> >
> > Thanks - will respond to your points below.
> >
> > On Tue, Jun 23, 2015 at 6:23 PM, Bob Carpenter
Just a quick comment that I don’t think we need to insist on precise 2.5% intervals. That’s old-style thinking, in which the goal of a statistical analysis is to check whether the 95% interval includes zero.
In practice, the interval [-1.9, 2.1] is as good as [-2, 2] or [-2, 1.9] or whatever.
> On Jun 23, 2015, at 6:41 PM, Bob Carpenter <ca...@alias-i.com> wrote:
>
> You need to run a lot of iterations to get good 2.5% intervals.
> And this is likely to be where we disagree with BUGS by getting
> more into tails. And this is also why Gibbs shouldn't be the gold
> standard. See the Betancourt and Girolami paper on hierarchical
> models.
To your points:
1. If you write the BUGS models with a bit of care, then they can be run with any of the three BUGS flavors. Just checkout the BUGSExamples package from Martyn Plummer. Only a handful of models need a single line of code different to run on JAGS.
2. I would like to be able to do something like this:
bugs_demo("winbugs_example_xy", engine="Stan") # this runs the "best practices" example in Stan; of course, the Stan engine will be the default
bugs_demo("winbugs_example_xy", engine="JAGS") # this runs the "best practices" example in JAGS or OpenBUGS or WinBUGS
bugs_demo("winbugs_example_xy", engine="JAGS", data="fake") # this runs the "best practices" example in JAGS or OpenBUGS or WinBUGS on fake data (which is also returned)
bugs_demo("winbugs_example_xy_vanilla", engine="JAGS") # this runs the vanilla example in JAGS or OpenBUGS or WinBUGS
3. This is really something which I do not ask for inclusion in this exercise here, but rather would like to be able to program it myself given that step 2 is done. Maybe a better wording is "with respect to the WinBUGS" result? The basic idea I am proposing is to first standardize the samples using robust estimators of the location and dispersion. This is essentially the same what Michael is suggesting and it effectively makes the 2-sample problem a 1-sample problem which is ok in this case, I think. And yes, going down to 2.5% and up to 97.5% requires a large sample size - using normal approximations one can get a handle on this.
Of course, the 2.5% steps are an arbitrary choice (one could even randomize this z-range which is compared), but then, the 95% is the magic number which is old, yes, but certainly used very often such that it is still up to date - at least for the people who are looking into this.
Best,
Sebastian
On Wednesday, June 24, 2015 at 12:42:36 AM UTC+2, Bob Carpenter wrote:
> > On Jun 23, 2015, at 3:33 PM,
> >