I just love the top line comment, and thought Andrew
would too, so I thought I'd call that out first:
## Un essai d'IRT avec Stan, le nouveau joujou d'Andrew Gelman.
On 9/8/12 6:25 PM, Emmanuel Charpentier wrote:
> I discovered Stan through Andrew Gelman's blog two days ago. The description was enticing, so I installed it and started
> to play around.
> I tried the "blocker" example of the BUGS manual vol 1 with no problems, and got a somewhat disappointing performance,
> when I compared it to the performance of JAGS on thsi very simple model. See attached blocker.(R|stan) file, which is
> annotated (and contains data).
Thanks for taking the time to try it and give us
feedback.
Responding to the note in the file, you're right that
Stan hasn't implemented random sample generation in the
generated quantities block. We're working on it!
For now, you can do what you did and define it in the
model, which is definitely slower.
We'll be speeding up the model considerably when we
vectorize all the distributions. This speedup will
scale with N.
> Most of the elapsed time was spent in compilation. This did not really surprise me : I did not expect the heavy
> compilation process of Stan to be as fast as the light compilation offered by JAGS. I was more surprised buy the fact
> that, even using only one processor, sampling from an already fit model was about 30% faster in JAGS. But again, the
> overhead entailed by a compilation to C++ might easily explain this in the case of such a tiny model.
When you say 30% faster, what exactly are you measuring?
Does that include the compilation time? Are both Stan
and JAGS giving roughly similar effective sample sizes?
Everyone uses their own ESS estimator.
There's a note in the Wiki on how to up the optimization
level of R's built-in compiler to -O3 (optimization level
3). That makes a big difference to Stan. It slows
down compilation considerably, while at the same time
substantially speeding up sampling.
You should only have to compile a model once.
> So I tried my hand at a problem I *knew* to be hard or JAGS : an IRT model (part of a larger model which can take
> *hours* to converge correctly on JAGS). This model follows largely Gelman & Hill's 2007 textbook.
>
> My first attempt on a dataset containing missing values failed for reasons I have not yet understood (but I understand
> that the released stan 1.0.0 is not yet complete...). So I wrote another model dealing only with full data. This time, I
> got a runtime error complaining about a negative infinite log-likelihood, which I have been unable to trace. As far as I
> can tell, all my initialisations are reasonable.
We're also planning to implement the models from
Gelman and Hill's book. The one you did is
a pretty straightforward model with a discrimination
term.
> Could you let me know where I goofed ?
I don't see anything obviously wrong in terms of
what Stan expects.
Did you try letting Stan do the initialization?
Stan initializes randomly uniformly on [-2,2]
on the unconstrained scale.
Positive-constrained parameters like your gamma
get a log transform to unconstrain them, and exp
transform to come back; so initializing around 0 on
the unconstrained scale initializes around 1.
You can set init=0 to get all-zero inits on the
unconstrained scale.
The binomial(1,inv_logit(phi)) could be replaced with
bernoulli_logit(phi); I saw you did that in some other
models. But Stan's pretty efficient at figuring out
which parts of the binomial calculation to do to get
the log probability up to a proportion.
> ## Error in function stan::prob::binomial_log<N4stan5agrad3varE>(N4stan5agrad3varE): Probability, theta, is nan:0,
> but must be finite!
The error you report is likely to arise if theta is
never initialized.
## SAMPLING FOR MODEL 'IRT1' NOW (CHAIN 1).
## Erreur dans sampler$call_sampler(args_list[[i]]) : variable ImpCp missing
I hope this is self explanatory. It's expecting to find
a variable and not finding it. If you want to do missing
data models in Stan, they have to be coded differently than
in BUGS/JAGS. There's a section in the programming part of
the manual with some examples.
I'll code up a version of the model you were trying
to debug and post it back to the list.
- Bob