truncation with *_log syntax?

13 views
Skip to first unread message

Seth Flaxman

unread,
Feb 20, 2016, 6:21:07 AM2/20/16
to stan-...@googlegroups.com
If I do:

y ~ normal(mu, sigma) T[0,ymax];

Can I do the equivalent with normal_log (I have a mixture model so can't use the above syntax), e.g.:

lp <- normal_log(y,mu,sigma) T[0,ymax];

And if this isn't supported at the moment, is there a hack or reparameterization for just a positively constrained normal distribution?

parameters {
   real<lower=0> y;
}
model {
   // ...
   lp <- normal_log(y,mu,sigma) T[0,];
}

In case you're interested in the model, I'm using a Gaussian mixture model for bivariate density estimation. Theoretically my data covers a really large range (time from 0 to 365 days, space from 0 to 20 km) but I'm only interested in a short-range model so I truncate my observations to 7 days and 2 km.

Thanks,
Seth

Daniel Lee

unread,
Feb 20, 2016, 8:37:07 AM2/20/16
to stan-...@googlegroups.com
Hi Seth,

On Feb 20, 2016, at 6:20 AM, Seth Flaxman <fla...@gmail.com> wrote:

If I do:

y ~ normal(mu, sigma) T[0,ymax];

Can I do the equivalent with normal_log (I have a mixture model so can't use the above syntax), e.g.:

lp <- normal_log(y,mu,sigma) T[0,ymax];

No. See "Truncated and Censored Data" and the subsection on "Truncated Distributions" (pg 280). 

You have to subtract the normalizing term: 
lp <- normal_log(y,mu,sigma) - log(normal_cdf(ymax, mu, sigma) - 0.5);

(What is lo declared as? You might want to use increment_log_prob() directly). 



And if this isn't supported at the moment, is there a hack or reparameterization for just a positively constrained normal distribution?

parameters {
   real<lower=0> y;
}
model {
   // ...
   lp <- normal_log(y,mu,sigma) T[0,];
}

If y is a scalar parameter with constraints, then there's no need to add T[lower, upper] (if the bounds match). Stan will behave as though you e provided the truncation. 

If you need to use it in a mixture model with different constraints, you may need to include the normalizing constants on your own. 



In case you're interested in the model, I'm using a Gaussian mixture model for bivariate density estimation. Theoretically my data covers a really large range (time from 0 to 365 days, space from 0 to 20 km) but I'm only interested in a short-range model so I truncate my observations to 7 days and 2 km.

Providing the full Stan model would be useful. 



Thanks,
Seth

--
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.

Bob Carpenter

unread,
Feb 20, 2016, 12:47:55 PM2/20/16
to stan-...@googlegroups.com
Just add in the appropriate log CDFs to normalize.
They're all spelled out in the manual, or you can
just take a look at how the C++ is generated for
the truncation.

We still don't have particularly numerically robust log CDFs or
log CCDFs yet --- now they're just doing the log of the CDF.

- Bob

> On Feb 20, 2016, at 6:20 AM, Seth Flaxman <fla...@gmail.com> wrote:
>

Bob Carpenter

unread,
Feb 20, 2016, 12:48:54 PM2/20/16
to stan-...@googlegroups.com
Ack. Sorry for repeating Daniel's answer.
I only saw it in my mailer after I responded.

- Bob
Reply all
Reply to author
Forward
0 new messages