stan-dev / posterior

The posterior R package
https://mc-stan.org/posterior/
Other
167 stars 24 forks source link

pareto_khat errors when it should just give a warning #315

Closed avehtari closed 5 months ago

avehtari commented 1 year ago
> pareto_khat(c(1e-4,rep(1,999)))
Error in if (ndraws_tail > S/2) { : missing value where TRUE/FALSE needed

> pareto_khat(c(1e-4,rep(1,999)), tail='right')
Error in seq.default(S - ndraws_tail + 1, S) : 
  'from' must be a finite number

also the following is a bit miseleading warning as 1) all values are finite, 2) smoothing was not requested

pareto_khat(rep(1,999), tail='right')
[1] NA
Warning message:
Input contains infinite or NA values, Pareto smoothing not performed. 
n-kall commented 1 year ago

I think this occurs because ess_tail(c(1e-4,rep(1,999)) returns NA (due to almost constant draws) in this case so the automatic calculation of relative efficiency ends up as NA, and so does the tail length. Should pareto_khat return NA in this case?

avehtari commented 1 year ago

I've started to think that maybe we should drop the relative efficiency adjustment of tail size. It is causing problems in edge cases. Anyway, for constant or almost constant such that tail would be constant, we can return NA, and give a warning

avehtari commented 1 year ago

Inconsistent return type

> str(pareto_smooth(rnorm(1000), tail='right', return_k=FALSE))
 num [1:1000] -0.136 -2.086 -1.33 -0.801 -0.612 ...

but

> str(pareto_smooth(rep(1,1000), tail='right', return_k=FALSE))
List of 2
 $ x          : num [1:1000] 1 1 1 1 1 1 1 1 1 1 ...
 $ diagnostics: num NA
Warning message:
Input contains infinite or NA values, Pareto smoothing not performed. 
n-kall commented 10 months ago

This should be fixed now by #314 Not yet fixed.