mitchelloharawild / distributional

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

hdr size is reversed? #61

Closed mjskay closed 3 years ago

mjskay commented 3 years ago

While looking at hdr, I just noticed that the intervals sizes seemed oddly small. I think the size parameter might be inverted...?

Example:

library(distributional)

# test with a normal since hdrs should be ~= hilos
x = dist_normal(0,1)

# correct at 50%
hdr(x, 50)
#> <list_of<hilo>[1]>
#> [[1]]
#> <hilo[1]>
#> [1] [-0.6744929, 0.6744929]50
hilo(x, 50)
#> <hilo[1]>
#> [1] [-0.6744898, 0.6744898]50

# inverted?
hdr(x, 95)
#> <list_of<hilo>[1]>
#> [[1]]
#> <hilo[1]>
#> [1] [-0.06393336, 0.06393336]95
hilo(x, 95)
#> <hilo[1]>
#> [1] [-1.959964, 1.959964]95
hdr(x, 5)
#> <list_of<hilo>[1]>
#> [[1]]
#> <hilo[1]>
#> [1] [-1.95194, 1.95194]5
hilo(x, 5)
#> <hilo[1]>
#> [1] [-0.06270678, 0.06270678]5

Created on 2021-07-05 by the reprex package (v2.0.0)

mitchelloharawild commented 3 years ago

Should be fixed now, thanks!

library(distributional)

test with a normal since hdrs should be \~= hilos

x = dist_normal(0,1)

correct at 50%

hdr(x, 50)
#> <list_of<hilo>[1]>
#> [[1]]
#> <hilo[1]>
#> [1] [-0.6744929, 0.6744929]50
hilo(x, 50)
#> <hilo[1]>
#> [1] [-0.6744898, 0.6744898]50

inverted?

hdr(x, 95)
#> <list_of<hilo>[1]>
#> [[1]]
#> <hilo[1]>
#> [1] [-1.95194, 1.95194]95
hilo(x, 95)
#> <hilo[1]>
#> [1] [-1.959964, 1.959964]95
hdrcde::hdr(generate(x, 1e6)[[1]], prob = 95)
#> $hdr
#>          [,1]     [,2]
#> 95% -1.955661 1.958104
#> 
#> $mode
#> [1] -0.0006906591
#> 
#> $falpha
#>         5% 
#> 0.06643554

hdr(x, 5)
#> <list_of<hilo>[1]>
#> [[1]]
#> <hilo[1]>
#> [1] [-0.06393336, 0.06393336]5
hilo(x, 5)
#> <hilo[1]>
#> [1] [-0.06270678, 0.06270678]5
hdrcde::hdr(generate(x, 1e6)[[1]], prob = 5)
#> $hdr
#>          [,1]       [,2]
#> 5% -0.1045826 0.02071713
#> 
#> $mode
#> [1] -0.05506228
#> 
#> $falpha
#>       95% 
#> 0.3982145

Created on 2021-07-06 by the reprex package (v2.0.0)