Can "normal_lpdf" give a positive result? Strange error

139 views
Skip to first unread message

Ste

unread,
Apr 11, 2017, 3:34:25 AM4/11/17
to Stan users mailing list
In attempting to calculate the probability of a 2D number to belong to a 2D cluster I am using normal_lpdf

transformed parameters{
for(i in 1:I) {
vector<upper=0>[2] cluster_log[G*P];
cluster_log[i,1] = normal_lpdf(.. | .., ..);
cluster_log[i,2] = normal_lpdf(.. | .., ..);
}
}

How is possible that normal_lpdf gives a positive result?

ERROR: cluster_log[k0__][1] is 1.45791, but must be less than or equal to 0" 

Thanks.

Ben Goodrich

unread,
Apr 11, 2017, 4:24:43 AM4/11/17
to Stan users mailing list
On Tuesday, April 11, 2017 at 3:34:25 AM UTC-4, Ste wrote:
How is possible that normal_lpdf gives a positive result?

Since a PDF is the slope of the CDF, it can go above 1 for a subset of the parameter space, in which case the log is positive. See for example

dnorm(0, mean = 0, sd = 0.25, log = TRUE) # 0.467

Ben

stefano

unread,
Apr 11, 2017, 5:03:44 AM4/11/17
to stan-...@googlegroups.com
Thank Ben,

So how can I translate that quantity in probability of a number to belong to a distribution?


--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/xahTgpKimBk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Goodrich

unread,
Apr 11, 2017, 5:19:05 AM4/11/17
to Stan users mailing list
On Tuesday, April 11, 2017 at 5:03:44 AM UTC-4, Ste wrote:
So how can I translate that quantity in probability of a number to belong to a distribution?

You can't.

Ben

Aki Vehtari

unread,
Apr 11, 2017, 6:15:26 AM4/11/17
to Stan users mailing list
Slightly longer answer: you need to understand the difference between probability density and probability mass. Density can be get values larger than 1, while probabilities are constrained to be less than or equal to 1.

stefano

unread,
Apr 11, 2017, 6:35:17 AM4/11/17
to stan-...@googlegroups.com
Thanks to both,

actually the short answer is the one I was also expecting. Thanks for the link!

Stefano Mangiola

Data analyst (MSc, MPhil, PhD candidate)
@ Melbourne University
Hovens lab - Papenfuss lab
Royal Melbourne Hospital - WEHI

Bob Carpenter

unread,
Apr 11, 2017, 3:19:35 PM4/11/17
to stan-...@googlegroups.com
You can in many cases look at posterior probabilities of mixture
responsibilities even for continuous outcomes. That may be what
you want and it's explained in the manual chapter on mixtures (or
the chapter on clustering).

We have to just guess when people send us fragments with no
explanation of their goals.

- Bob

> On Apr 11, 2017, at 6:35 AM, stefano <mangiol...@gmail.com> wrote:
>
> Thanks to both,
>
> actually the short answer is the one I was also expecting. Thanks for the link!
>
> Stefano Mangiola
>
> Data analyst (MSc, MPhil, PhD candidate)
> @ Melbourne University
> Hovens lab - Papenfuss lab
> Royal Melbourne Hospital - WEHI
> +61 (0)450135954
>
> 2017-04-11 20:15 GMT+10:00 Aki Vehtari <aki.v...@aalto.fi>:
> Slightly longer answer: you need to understand the difference between probability density and probability mass. Density can be get values larger than 1, while probabilities are constrained to be less than or equal to 1.
> See more, e.g., in https://en.wikipedia.org/wiki/Probability_density_function
>
>
> On Tuesday, April 11, 2017 at 12:19:05 PM UTC+3, Ben Goodrich wrote:
> On Tuesday, April 11, 2017 at 5:03:44 AM UTC-4, Ste wrote:
> So how can I translate that quantity in probability of a number to belong to a distribution?
>
> You can't.
>
> Ben
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/xahTgpKimBk/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>
>
> --
> 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.
Reply all
Reply to author
Forward
0 new messages