Hurdle Model from Manual

341 views
Skip to first unread message

Cody Ross

unread,
Dec 13, 2014, 7:27:27 PM12/13/14
to stan-...@googlegroups.com
The hurdle model is define in the manual as:
The hurdle model is even more straightforward to program in Stan, as it does not
require an explicit mixture.

y
[n] ~ bernoulli(theta);
if (y[n] > 0)
y
[n] ~ poisson(lambda) T[1,];

The [1,] after the Poisson indicates that it is truncated below at 1; see Section 37.3.
Although the variable y[n] is being sampled twice, the effect on the log probability
fucntion follows the definition
(on the log scale).

How is this possible? Is there a missing "(if y[n]=0)" statement before the first statement above? Or does y[n] actually need to be 'sampled twice'? How can y[n] be sampled from a Bernoulli if it is >1?

Andrew Gelman

unread,
Dec 13, 2014, 7:38:02 PM12/13/14
to stan-...@googlegroups.com
Hi, I’m not sure but, just speaking generally, the statement “~” in a Stan model does _not_ represent sampling, it represents a term in the log-posterior.
A

--
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.
For more options, visit https://groups.google.com/d/optout.

Marco Inacio

unread,
Dec 13, 2014, 8:39:06 PM12/13/14
to stan-...@googlegroups.com


> How can y[n] be sampled from a Bernoulli if it is >1?
You're right, if you follow the notation of manual for Hurdle
distribution, it should be:

(y[n] == 0) ~ bernoulli(theta);
if (y[n] > 0)
y[n] ~ poisson(lambda) T[1,];


Example:

stanm2 <- stan_model(model_code="
data {
int y[3];
}
parameters {
real<lower=0, upper=1> theta;
real<lower=0> lambda;
}
model {
for (n in 1:3) {
(y[n] == 0) ~ bernoulli(theta);
if (y[n] > 0)
y[n] ~ poisson(lambda) T[1,];
}
}")

fit1 <- sampling(stanm2, chains = 2, iter = 1e4, data = list(y = c(1,2,0)))

Cody Ross

unread,
Dec 13, 2014, 8:43:24 PM12/13/14
to stan-...@googlegroups.com

 Excellent,
Thanks for the quick reply.

Bob Carpenter

unread,
Dec 14, 2014, 4:07:50 PM12/14/14
to stan-...@googlegroups.com
That was my fault --- I should've run it on simulated data.
Thanks for diagnosing, Marco.

- Bob

> On Dec 13, 2014, at 8:43 PM, Cody Ross <ctr...@ucdavis.edu> wrote:
>
>
> Excellent,
> Thanks for the quick reply.
>
Reply all
Reply to author
Forward
0 new messages