Skip to contents

A distribution parameterized by a set of quantiles

Usage

dist_quantiles(values, quantile_levels)

Arguments

values

A vector (or list of vectors) of values.

quantile_levels

A vector (or list of vectors) of probabilities corresponding to values.

When creating multiple sets of values/quantile_levels resulting in different distributions, the sizes must match. See the examples below.

Value

A vector of class "distribution".

Examples

dist_quantiles(1:4, 1:4 / 5)
#> <distribution[1]>
#> [1] quantiles(2.5)[4]
dist_quantiles(list(1:3, 1:4), list(1:3 / 4, 1:4 / 5))
#> <distribution[2]>
#> [1] quantiles(2)[3]   quantiles(2.5)[4]
dstn <- dist_quantiles(list(1:4, 8:11), c(.2, .4, .6, .8))
dstn
#> <distribution[2]>
#> [1] quantiles(2.5)[4] quantiles(9.5)[4]

quantile(dstn, p = c(.1, .25, .5, .9))
#> [[1]]
#> [1] 0.2952896 1.2500000 2.5000000 4.8267802
#> 
#> [[2]]
#> [1]  7.29529  8.25000  9.50000 11.82678
#> 
median(dstn)
#> [1] 2.5 9.5

# it's a bit annoying to inspect the data
distributional::parameters(dstn[1])
#>       values    quantile_levels
#> 1 1, 2, 3, 4 0.2, 0.4, 0.6, 0.8
nested_quantiles(dstn[1])[[1]]
#> # A tibble: 4 × 2
#>   values quantile_levels
#>    <dbl>           <dbl>
#> 1      1             0.2
#> 2      2             0.4
#> 3      3             0.6
#> 4      4             0.8