-
Notifications
You must be signed in to change notification settings - Fork 16
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
Inaccurate HDRs #123
Comments
This is largely based on the grid size of the quantiles (same as is done in hdrcde). Gradient descent based methods would produce more accurate solutions starting from suitable hdrs from the grid method. library(distributional)
hdr(dist_normal(), n = 1e6)
#> <hdr[1]>
#> [1] [-1.959956, 1.959956]95
qnorm(0.975)
#> [1] 1.959964 Created on 2024-08-12 with reprex v2.1.0 |
Maybe set n a little higher. quantiles should be relatively quick to compute for most distributions. Setting n=1e5 is still relatively quick for |
What do you think about root finding algorithms for this, starting from a suitable location chosen from a course grid? |
Maybe. Perhaps try a speed comparison on library(distributional)
library(ggplot2)
df <- data.frame(
n = exp(seq(log(50), log(5e3), length = 1e3)),
upper = NA_real_
)
for (i in seq(NROW(df))) {
df$upper[i] <- unlist(hdr(dist_normal(), n = df$n[i]))["upper"]
}
df |>
ggplot(aes(x = n, y = upper)) +
geom_line() +
geom_hline(yintercept = qnorm(0.975), col = "red") +
scale_x_log10() Created on 2024-09-17 with reprex v2.1.1 |
I started writing a root finding function, and then realised why I didn't do it this way in the first place. Every time you do a calculation of the HDR coverage for a generic continuous distribution, you need to compute the density at a large number of observations, because the algorithm uses Monte Carlo integration. So with root finding, it would require far more computations than having a fine grid. Of course, we could have I can do a PR along these lines if you want. |
Created on 2024-08-12 with reprex v2.1.1
The text was updated successfully, but these errors were encountered: