Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hdr()$hdr sometimes contains only left bound, sometimes only right bound #3

Closed
hughjonesd opened this issue Nov 3, 2018 · 4 comments

Comments

@hughjonesd
Copy link

Examples:

# right bound only
hdrcde::hdr(den = list(x = x<- 0:100/100, y = dbeta(x, 1, 2)), prob = 99)$hdr
    [,1]
99%  0.9

# left bound only
hdrcde::hdr(den = list(x = x<- 0:10000/10000, y = dbeta(x, 2, 1)), prob = 99)$hdr
        [,1]
99% 0.107195

This means consuming code has to guess which interval is which. A workaround is to include e.g. prob = c(99, 0.01).

My version: 3.2 from github.

@robjhyndman
Copy link
Owner

The "workaround" does not fix the issue. The problem is that the densities provided are essentially triangular.

x <- seq(0,1,l=1000)
hdrcde::hdr.den(den = list(x = x, y = dbeta(x, 1, 2)), prob = 99)$hdr
hdrcde::hdr.den(den = list(x = x, y = dbeta(x, 2, 1)), prob = 99)$hdr

The function does not know what happens to the density outside the range (0,1). The best solution is to expand the range slightly.

x <- seq(-0.01,1.01,l=1000)
hdrcde::hdr(den = list(x = x, y = dbeta(x, 1, 2)), prob = 99)$hdr
hdrcde::hdr(den = list(x = x, y = dbeta(x, 2, 1)), prob = 99)$hdr

@hughjonesd
Copy link
Author

I see. But if I include the second density, it does solve part of my problem, because I get a NA back, instead of just a single column without a name. So then at least I know which bound could not be determined.

So I think there are two issues here: the not knowing what the density is at 0 and 1; and the fact that only one column is returned when only one prob is requested.

@vittorioorlandi
Copy link

I'm having this same problem, with 3 or sometimes 5 endpoints being returned. However, the density is smooth (I've even had this problem with practically normal densities), the probability is 0.95 (not very close to 1), and the HDR intervals should not (as far as I can tell) go beyond the range of the data.

I've attached a reproducible example.
hdrcde_bug.R.zip

@robjhyndman
Copy link
Owner

All these problems should now be fixed in the latest commit: 3db6f9b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants