Hi Jonas,
First, thank you for maintaining kdensity! It's a fantastic package and the native support for Chen's beta kernels is incredibly useful for bounded data.
I am reaching out because I recently had a paper accepted in the Journal of Computational and Graphical Statistics (JCGS) that solves a major practical bottleneck for beta kernels: the lack of a fast, closed-form bandwidth selector. Currently, practitioners usually rely on numerical LSCV, which can be computationally expensive and occasionally unstable for extreme bounded data.
I derived the "Beta Reference Rule" (analogous to Silverman's rule), which reduces the bandwidth selection to an $O(1)$ operation with an automatic fallback heuristic for J/U-shaped distributions.
Since kdensity already has the excellent beta kernel infrastructure, I thought this might be a great fit as a new bandwidth option (e.g., bw = "beta-rot") for your users.
Here is a quick reproducible example showing how it plugs directly into your package:
# Source the standalone bandwidth selector
source("https://raw.githubusercontent.com/egonmedhatten/beta-kde/main/beta_bw.R")
# Generate bounded data
set.seed(42)
my_data <- rbeta(500, 2, 5)
# Calculate the optimal rule-of-thumb bandwidth
h_opt <- bw.beta.rot(my_data)
cat("Optimal bandwidth:", h_opt, "\n")
# Plug it directly into kdensity
library(kdensity)
fit <- kdensity(my_data, kernel = "beta", bw = h_opt)
plot(fit, main = "Beta KDE with Rule-of-Thumb Bandwidth")
I know package maintenance takes a lot of free time, so there is absolutely no pressure to implement this immediately. I just wanted to provide the math and the code in case you'd like to include it in a future CRAN release. If there is anything I can do to help (like submitting a Pull Request), please let me know!
Best regards,
Johan Hallberg Szabadváry
Hi Jonas,
First, thank you for maintaining
kdensity! It's a fantastic package and the native support for Chen's beta kernels is incredibly useful for bounded data.I am reaching out because I recently had a paper accepted in the Journal of Computational and Graphical Statistics (JCGS) that solves a major practical bottleneck for beta kernels: the lack of a fast, closed-form bandwidth selector. Currently, practitioners usually rely on numerical LSCV, which can be computationally expensive and occasionally unstable for extreme bounded data.
I derived the "Beta Reference Rule" (analogous to Silverman's rule), which reduces the bandwidth selection to an$O(1)$ operation with an automatic fallback heuristic for J/U-shaped distributions.
Since
kdensityalready has the excellent beta kernel infrastructure, I thought this might be a great fit as a new bandwidth option (e.g.,bw = "beta-rot") for your users.Here is a quick reproducible example showing how it plugs directly into your package:
I know package maintenance takes a lot of free time, so there is absolutely no pressure to implement this immediately. I just wanted to provide the math and the code in case you'd like to include it in a future CRAN release. If there is anything I can do to help (like submitting a Pull Request), please let me know!
Best regards,
Johan Hallberg Szabadváry