mitchelloharawild / distributional

Vectorised distributions for R
https://pkg.mitchelloharawild.com/distributional
GNU General Public License v3.0
97 stars 15 forks source link

quantile() applied to dist_transformed() with multiple probs adds an extra nesting level to output list #70

Closed mjskay closed 2 years ago

mjskay commented 2 years ago

It appears that each application of dist_transformed() causes an extra nesting level to be added in the output list of quantile() when using quantile() with multiple probabilities. E.g.:

> x = dist_normal(0:1,1)
> str(quantile(x, c(0, 0.5, 1)))
List of 2
 $ : num [1:3] -Inf 0 Inf
 $ : num [1:3] -Inf 1 Inf
> str(quantile(exp(x), c(0, 0.5, 1)))
List of 2
 $ :List of 1
  ..$ : num [1:3] 0 1 Inf
 $ :List of 1
  ..$ : num [1:3] 0 2.72 Inf
> str(quantile(log(exp(x)), c(0, 0.5, 1)))
List of 2
 $ :List of 1
  ..$ :List of 1
  .. ..$ : num [1:3] -Inf 0 Inf
 $ :List of 1
  ..$ :List of 1
  .. ..$ : num [1:3] -Inf 1 Inf

Where the output in all cases should have the same shape as the first call to quantile on the untransformed distribution.

(I tested this on the latest github version on master)

With only a single probability there is no problem:

> str(quantile(log(exp(x)), 0.5))
 num [1:2] 0 1
mitchelloharawild commented 2 years ago

Resolved in https://github.com/mitchelloharawild/distributional/commit/9dc15562b6ff7f0e9c1e0aaba478e62407bf9ae7