[moving to stan-dev]
On Apr 21, 2014, at 9:53 AM, Andrew Gelman <
gel...@stat.columbia.edu> wrote:
> Hi, the following model does not work:
...
> y ~ bernoulli(normal_cdf(X*b,0,1));
>
> But it seems to work when I change the model statement to:
>
> for (n in 1:N)
> y[n] ~ bernoulli(normal_cdf(X[n]*b,0,1));
...
> Is it a problem with vectorization?
That's a feature, not a bug, as they say.
Like our other vectorized functions, normal cdf is defined so that
normal_cdf(v,mu,sigma)
= SUM_k normal_cdf(v[k],mu[k],sigma[k])
The mu and sigma get implicitly broadcast by copying to
a vector if they are scalars.
Although this matches the log density function vectorization behavior,
it doesn't make as much sense to add CDF values!
Should we either (a) un-vectorize these, or (b) change the behavior to
return a vector?
At the very least, I think the doc should be clearer that the vectorization
works the same way for log densities and CDFs.
> I also tried Phi() and the same thing happened.
The version with Phi won't compile because Phi isn't
vectorized. One easy project for some volunteer to take on would
be vectorizing all of our scalar functions. I added some notes on how
we can use functionals and functors to automatically define vectorization
for our scalar functions:
https://github.com/stan-dev/stan/wiki/Functor-Functional-Design-for-Special-Functions
- Bob