Learn R Programming

rbbnp

A Bias Bound Approach to Non-parametric Inference

This is an affiliated package for Susanne M Schennach, A Bias Bound Approach to Non-parametric Inference, The Review of Economic Studies, Volume 87, Issue 5, October 2020, Pages 2439–2472, https://doi.org/10.1093/restud/rdz065

version 0.3.0

Build up the package for your first time to use

Example: See the help documentation of a function

?biasBound_density

Load package

library(rbbnp)

Example Code

Loading Sample data

# Generate sample dataset
X = gen_sample_data(size = 1000, dgp = "2_fold_uniform", seed = 123456)
Y = -X^2 + 3*X + rnorm(1000)*X

For Stata/SAS/SPSS format dataset, one can use the haven package to load the dataset.

# Example for loading the Stata file
library(haven)
sample_data <- read_dta(file.path(EXT_DATA_PATH, "sample_data.dta"))
sample_data
# A tibble: 1,000 × 2
#        X     Y
#    <dbl> <dbl>
#  1 1.09  2.83 
#  2 1.63  2.01 
#  3 1.23  3.35 
#  4 1.07  1.95 
#  5 0.844 1.39 
#  6 0.879 1.95 
#  7 1.49  1.62 
#  8 0.699 2.04 
#  9 1.38  0.528
# 10 0.866 2.83 
# ℹ 990 more rows
# ℹ Use `print(n = ...)` to see more rows

1. Density estimation biasBound_density() function

If x is specified it will return the point estimation

biasBound_density(X = X, x = 1, h = 0.09, alpha = 0.05, if_plot_ft = TRUE, kernel.fun = "Schennach2004")
# $est_Ar
# est_A    est_r 
# 4.297778 1.998942 
# 
# $b1x
# [1] 0.1270842
# 
# $ft_plot
# 
# $f1x
# [1] 0.9598753
# 
# $CI
# lb        ub 
# 0.7245948 1.1951559 

If not, it returns the estimation over the whole range of X

biasBound_density(X = X, h = 0.09, alpha = 0.05, if_plot_ft = TRUE, kernel.fun = "Schennach2004")

2. Conditional Mean estimation biasBound_condExpectation() function

If x is specified, it returns the point estimation of $E(Y|X = x)$

biasBound_condExpectation(Y = Y, X = X, x = 1, h = 0.09, alpha = 0.05, kernel.fun = "Schennach2004")

# $conditional_mean_yx
# [1] 2.001679
# 
# $CI
# lb       ub 
# 1.501453 2.609014 

If not, it returns the estimation over the whole range of X

biasBound_condExpectation(Y = Y, X = X, h = 0.09, alpha = 0.05, kernel.fun = "Schennach2004")

3. Fourier Transform frequency $\xi$ interval selection

The Fourier Transform frequency $\xi$ plays an important role in our bias bound approach. Specifically, it determines the range in which a nonparametric estimation the key parameters total variation $A$ and order of differentiability $r$ of the unknown distribution function. By default, it is determined by the Theorem 2 in Schennach (2020).

Here is an example how we can customize the range of $\xi$ when performing the density and conditional expectation estimation.

# Example 1: Specifying x for point estimation with manually selected xi range from 1 to 12
biasBound_density(X = sample_data$X, x = 1, h = 0.09, xi_lb = 1, xi_ub = 12)
# $est_Ar
# est_A    est_r 
# 5.569499 2.229150 
# 
# $b1x
# [1] 0.07771575
# 
# $ft_plot

# Example 2: Density estimation with manually selected xi range from 1 to 12 xi_lb and xi_ub
biasBound_density(X = sample_data$X, h = 0.09, xi_lb = 1, xi_ub = 12, if_plot_ft = FALSE)

# Example 3: conditional expectation of Y on X with manually selected range of xi
biasBound_condExpectation(Y = sample_data$Y, X = sample_data$X, h = 0.09, xi_lb = 1, xi_ub = 12)

4. Kernel selection

We provide several options for kernel function, such as sinc, normal and epanechnikov kernel.

biasBound_density(X = sample_data$X, h = 0.09, methods_get_xi = "Schennach", if_plot_ft = TRUE, kernel.fun = "epanechnikov")

Copy Link

Version

Install

install.packages('rbbnp')

Monthly Downloads

158

Version

0.3.0

License

GPL (>= 3)

Maintainer

Xinyu DAI

Last Published

April 30th, 2025

Functions in rbbnp (0.3.0)

normal_kernel_ft

Fourier Transform of Normal Kernel
get_est_b1x

Estimation of bias b1x
plot_ft

Plot the Fourier Transform
select_bandwidth

Select Optimal Bandwidth
silverman_bandwidth

Silverman's Rule of Thumb for Bandwidth Selection
get_sigma

Estimation of sigma
get_est_vy

get the estimation of Vy
get_sigma_yx

Estimation of sigma_yx
get_xi_interval

get xi interval
kernel_reg

Kernel Regression function
true_density_2fold

True density of 2-fold uniform distribution
normal_kernel

Normal Kernel Function
rpoly01

Generate n samples from the distribution
get_conditional_var

get the conditional variance of Y on X for given x
sample_data

Sample Data
get_est_byx

Estimation of bias byx
sinc

Infinite Kernel Function
sinc_ft

Define the closed form FT of the infinite order kernel sin(x)/(pi*x)
DATA_PATH

The Path to the Data Folder
create_kernel_functions

Create kernel functions based on configuration
W_kernel

Define the inverse Fourier transform function of W
biasBound_density

Bias bound approach for density estimation
biasBound_condExpectation

Bias bound approach for conditional expectation estimation
cv_bandwidth

Cross-Validation for Bandwidth Selection
epanechnikov_kernel

Epanechnikov Kernel
W_kernel_ft

Define the Fourier transform of a infinite kernel proposed in Schennach 2004
create_biasBound_config

Create a configuration object for bias bound estimations
EXT_DATA_PATH

The Path to the External Data Folder for Non-R Data Files
get_avg_phi_log

Compute log sample average of fourier transform and get mod
epanechnikov_kernel_ft

Fourier Transform Epanechnikov Kernel
get_avg_f1x

Kernel point estimation
get_est_Ar

get the estimation of A and r
fun_approx

Approximation Function for Intensive Calculations
get_est_B

get the estimation of B
get_avg_fyx

Kernel point estimation
gen_sample_data

Generate Sample Data
get_avg_phi

Compute Sample Average of Fourier Transform Magnitude