Get Started with rbbnp
Xinyu Dai and Susanne M. Schennach
2026-02-14
rbbnp.RmdOverview
The rbbnp package implements a novel bias-bound approach to nonparametric inference developed by Schennach (2020). The key insight is that while we cannot consistently estimate pointwise bias, we can estimate an upper bound on bias magnitude, enabling valid confidence intervals with optimal bandwidths.
Installation
# Install from CRAN
install.packages("rbbnp")
# Or install development version from GitHub
# install.packages("devtools")
devtools::install_github("xinyu-daidai/rbbnp-dev")Quick Start
Density Estimation
# Generate sample data
X <- gen_sample_data(size = 500, dgp = "2_fold_uniform", seed = 123456)
# Estimate density with bias-aware confidence intervals
fit <- biasBound_density(X, h = 0.1, kernel.fun = "Schennach2004")
# View summary
fit
#> Bias-Bounded Density Estimation
#>
#> Call:
#> biasBound_density(X = X, h = 0.1, kernel.fun = "Schennach2004")
#>
#> Sample size: n = 500
#> Bandwidth: h = 0.1000 (user-specified)
#> Kernel: Schennach2004
#>
#> Bias bound parameters:
#> A = 3.3985, r = 1.8166
#> bias bound b1x = 0.2063
#>
#> Evaluation points: 100 (range: [-0.1639, 2.0517])
#> Confidence level: 95%
#>
#> Use summary() for detailed statistics
#> Use plot() to visualize results
# Visualize results
plot(fit)
The plot shows:
- Blue line: Estimated density
- Orange band: Bias range where true lies
- Green band: 95% confidence interval
Conditional Expectation (Regression)
# Generate regression data: Y = -X^2 + 3X + noise
Y <- -X^2 + 3*X + rnorm(500) * X
# Estimate conditional expectation
fit_reg <- biasBound_condExpectation(Y, X, h = 0.1, kernel.fun = "Schennach2004")
# Visualize
plot(fit_reg)
Working with Results
Both functions return S3 objects with standard methods:
# Extract parameters
coef(fit)
#> A r h
#> 3.398493 1.816558 0.100000
# Get confidence intervals
head(confint(fit))
#> lower upper
#> [1,] 0 0.2062650
#> [2,] 0 0.2062650
#> [3,] 0 0.2062650
#> [4,] 0 0.2062650
#> [5,] 0 0.2169229
#> [6,] 0 0.2309202
# For regression: get fitted values
head(fitted(fit_reg))
#> [1] 0.0420927 0.1386661 0.2211023 0.2938845 0.3597238 0.4202832Next Steps
- Density Estimation: Detailed guide to density estimation
- Regression: Conditional expectation estimation
- Theory: Mathematical background
References
Schennach, S. M. (2020). A Bias Bound Approach to Non-parametric Inference. The Review of Economic Studies, 87(5), 2439-2472. doi:10.1093/restud/rdz065