Mixture model where one component is beta distribution and one is a delta function

533 views
Skip to first unread message

Mike Williams

unread,
Jun 30, 2016, 7:01:31 PM6/30/16
to stan-...@googlegroups.com
I'd like to model a fraction in the range 0 to 1. One component of the mixture is well described by a beta distribution. The problem is the other component is a delta function at 1.

To be concrete, imagine the fraction represents something like how full gas tanks are in cars leaving a gas station. Some fraction theta are exactly 100% full. The remainder, 1-theta are somewhere between 0 and 100% full, perhaps beta(a, b). The parameters theta, a and b could be linear functions of the observed features (model of car, time of day, etc.)

Can I solve this in a single model in stan, where the parameters theta, a and b are correlated?

Or do I need to decompose it into two problems (1) a bernoulli model to infer the posterior on theta, for the binary question: is the tank full or not? and separately (2) for the subset of observations with non-full tanks, the beta distribution model for the fraction?

Or am I missing some other approach?

And does this class of problems have a name? Pointers most welcome!

Mike

Andrew Gelman

unread,
Jun 30, 2016, 7:14:02 PM6/30/16
to stan-...@googlegroups.com
Hi, is this is a hierarchical model, or do you have direct data? If it's direct data (i.e., you observe the gas tank level directly), then there is a simple solution. Let y be your data, numbers between 0 and 1 representing tank level.
Define z = 1 if y=1 or 0 otherwise.
First, run a logistic regression to predict z given your predictors. That's your first model.
Second, fit a model for y, but just on the data for which z=0 (that is, the non-full tank) to estimate your continuous model. Rather than a beta distribution, you might want to use a lognormal as then the parameters are easier to interpret.
You can fit the models together in one Stan program.
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.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


Michael Betancourt

unread,
Jun 30, 2016, 7:24:07 PM6/30/16
to stan-...@googlegroups.com
This is essentially a zero-inflation model, just with
one-inflation instead of zero-inflation. See Section 10.6
of the manual.

Andrew Gelman

unread,
Jun 30, 2016, 7:32:11 PM6/30/16
to stan-...@googlegroups.com
No, it's simpler than a zero-inflation model. With the classic zero-inflated Poisson, the challenge is that data zeroes can come from the regular Poisson model (which can produce values of 0, 1, 2, etc) or from the zero-inflated part. Mike W's example is a mixture of a discrete and continuous distribution: _all_ his 1's come from the discrete "full tank" component of the model, and all his non-1's come from the continuous part of his model. The separation is clean.
A

Michael Williams

unread,
Jun 30, 2016, 11:15:26 PM6/30/16
to Stan users mailing list, gel...@stat.columbia.edu
Hi Andrew,

thanks! Gas tank level in this case is not a latent feature. It's the observable.

My concern with the approach you describe is that I don't see how to pool information. In your notation, classes of car that are more likely to have z=1 also have higher average y (when y < 1). So I'd like latent structure that captures this covariance between a, b, mu and sigma. If there's a single feature, x, I have something like

z ~ bernoulli_logit(a + b * x)
y ~ lognormal(mu * x, sigma)

I'm new at this, but I don't see a choice of prior(s) on a, b, mu and sigma that will capture the relationship between them.

Mike

Michael Williams

unread,
Jun 30, 2016, 11:21:50 PM6/30/16
to Stan users mailing list, gel...@stat.columbia.edu
Sorry one additional point:

The other difficulty I have with this approach is I'm unsure of the right way to efficiently generate samples from y in the generated quantities block, since the lognormal distribution doesn't do it. Do I need an if-then-else structure to first generate a z, and then set y = 1 if z = 1, or sample from the lognormal if z = 0? Or is there a better way?

Mike

Andrew Gelman

unread,
Jun 30, 2016, 11:36:23 PM6/30/16
to Michael Williams, Stan users mailing list
1.  You can fit two regression models and start with independent priors on the parameters of the models.  If you want to link those parameters in some way, that's fine, but I'd say it's best to start and see what the data say.

2.  Yes, you first generate from the bernoull-logistic to get the 0/1 variable, then if that's not 1, you generate from the lognormal.  That's the way to do it.

Michael Betancourt

unread,
Jul 1, 2016, 4:29:49 AM7/1/16
to stan-...@googlegroups.com
But if the tank saturation is being measured then there’s no difference —
from the continuous model a perfectly full tank is measure zero and essentially
trivial compared to the Dirac distribution at 1. The 1-inflation model would
essentially decouple into two independent models (it’s not an exact decoupling
because you could still get 1’s from the beta distribution!).

This won’t work for a latent, unmeasured model, but as a measurement model
it’s worked for me in the past.

Bob Carpenter

unread,
Jul 6, 2016, 9:21:05 PM7/6/16
to stan-...@googlegroups.com
The code's the same as for any mixture. lp1 and lp2 are
the log densities for the mixture component, theta is the
mixture proportion and log_mix(theta, lp1, lp2) is the
way to code it. We need to update some of the discussion of
mixtures in the manual to use the more efficient log_mix function.
And we could use one on the logit scale for theta.

The ecologists do zero inflation for models for animal
movement when they don't move. The other component is
a positive-constrained continuous density.

- Bob

P.S. The "hurdle" model is a pure mixture, but that's with
a truncated Poisson that doesn't produce zeroes. At least
it's two pmfs. In this case, it's a pmf and a pdf, which is
OK, but doesn't fit into intro math stats books because it's
neither a pdf or pmf itself!
Reply all
Reply to author
Forward
0 new messages