posterior icon indicating copy to clipboard operation
posterior copied to clipboard

pareto_khat errors when it should just give a warning

Open avehtari opened this issue 2 years ago • 4 comments
trafficstars

> 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. 

avehtari avatar Nov 15 '23 13:11 avehtari

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?

n-kall avatar Nov 15 '23 14:11 n-kall

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 avatar Nov 15 '23 15:11 avehtari

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. 

avehtari avatar Nov 15 '23 16:11 avehtari

This should be fixed now by #314

n-kall avatar Jan 10 '24 13:01 n-kall