paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.25k stars 177 forks source link

"Error: 'p' must contain probabilities in (0,1)" in qstudent_t(1, df = 3), qskew_normal and a few others #1637

Closed venpopov closed 3 months ago

venpopov commented 3 months ago

I was trying to visualize some distributions defined in brms, for example the student_t, via ggdist and the distributional package. For some distributions it works fine:

library(ggplot2)
library(ggdist)
library(distributional)
library(brms)
dist1 <- dist_wrap('shifted_lnorm', package = 'brms')
ggplot() +
  stat_halfeye(aes(xdist = dist1))

image

but for others such as student_t, skew_normal, there is an error:

dist1 <- dist_wrap('student_t', package = 'brms', df = 3)
ggplot() +
  stat_halfeye(aes(xdist = dist1))
#> Error in `layer_slabinterval()`:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error:
#> ! 'p' must contain probabilities in (0,1)

Created on 2024-03-29 with reprex v2.1.0

This is because for some distributions (but not all), the code here gives an error if p=0 or p=1 in a quantile function. Is there a particular reason to reject these values rather than returning +- Inf, as for example stats::qt(p=1) does?

paul-buerkner commented 3 months ago

No particular reason, p=0 and p=1 should for allowed. Would it be possible for you to do a PR to fix this?

venpopov commented 3 months ago

sure