
Get Started with rbbnp
rbbnp.RmdOverview
The rbbnp package implements the bias-bound approach to nonparametric inference of Schennach (2020). At an MSE-oriented bandwidth a kernel estimator carries non-negligible smoothing bias, so a conventional standard-error interval need not cover its target. The bias-bound approach estimates an upper bound on the magnitude of that bias and adds it to the interval:
\[CI = [\hat{f} - \bar{b} - z_{1-\alpha/2}\hat{\sigma}, \quad \hat{f} + \bar{b} + z_{1-\alpha/2}\hat{\sigma}]\]
where \(\bar{b}\) is the estimated bias bound and \(z_{1-\alpha/2}\) is the standard-normal critical value. Under the smoothness, window, and kernel conditions in Schennach (2020), the result prioritizes validity at the selected bandwidth; its price is conservatism, and the interval can be wider than an undersmoothed conventional interval.
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 two-fold-uniform data
set.seed(123456)
x <- runif(500) + runif(500)
# Estimate density with bias-aware confidence intervals
fit <- bias_bound_density(x, bw = 0.1, kernel = "schennach")
# View summary
fit
#> Bias-Bounded Density Estimation
#>
#> Call:
#> bias_bound_density(x = x, bw = 0.1, kernel = "schennach")
#>
#> Sample size: n = 500
#> Bandwidth: h = 0.1000 (user-specified)
#> Kernel: Schennach2004
#>
#> Bias bound parameters:
#> A = 4.1964, r = 2.0000
#> bias bound b1x = 0.1374
#>
#> 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 (the legend labels each element):
- Estimate: the estimated density \(\hat{f}(x)\)
- Bias bound: the range where \(E[\hat{f}]\) may lie
- 95% CI: the 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 <- bias_bound_regression(x, y, bw = 0.1, kernel = "schennach")
# Visualize
plot(fit_reg)
Working with Results
Both functions return S3 objects with standard methods:
# Extract parameters
coef(fit)
#> A r h
#> 4.196374 2.000000 0.100000
# Get confidence intervals
head(confint(fit))
#> lower upper
#> [1,] 0 0.1373845
#> [2,] 0 0.1373845
#> [3,] 0 0.1373845
#> [4,] 0 0.1373845
#> [5,] 0 0.1480424
#> [6,] 0 0.1620397
# 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