Learn R Programming

LPCDE

The lpcde package provides R implementation for bandwidth selection, point estimation and inference for local polynomial conditional distribution and density methods.

This work was supported by the the National Science Foundation through grants SES-1947805, SES-1947662, DMS-2210561, and SES-2241575, and from the National Institute of Health (R01 GM072611-16).

Website

https://nppackages.github.io/lpcde

R Implementation

To install/update in R type:

install.packages('lpcde')

Here we outline some of the simple use cases of the package. For a given dataset, comprising of a response variable (y_data) and a collection of regressors (x_data), the lpcde function estimates the conditional distribution (or derivatives thereof) at some prescribe value of x. By default a locally quadratic polynomial in y and locally linear polynomial in x and Epanechnikov kernel are used on some prescribed values of y, y_grid, with a bandwidth bw. This procedure is executed with the following command:

model1 = lpcde::lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw=1)

Standard R methods, coef, confint, vcov, print, plot and summary, can be used on objects returned from the lpcde function to understand the output. For example, the summary command applied to the object generated from this function, summary(model1), will output a table that provides the point estimates of the conditional density, number of data points used in estimation, standard error, and a robust 95% confidence interval. The confidence level, robustness of point and standard error estimates, estimates of uniform confidence bands can all be altered by providing the correct inputs to the optional variables for the lpcde function.

By default, the function provides estimates according to the original formulation of the estimator (see references below for all technical details). If a constrained density estimate that is non-negative and integrates to one is desired (see references below), the flags nonneg and normalize can be turned on:

model_reg = lpcde::lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw=1,
                        nonneg=TRUE, normalize=TRUE)

The package also provides additional an function for automating the bandwidth selection, lpbwcde. By default this function computes the rule-of-thumb MSE optimal bandwidth for the conditional PDF with locally quadratic polynomial in y and locally linear polynomial in x and Epanechnikov kernel on the implied support of Y.

model2 = lpbwcde(y_data = y_data, x_data = x_data, x = 0, y_grid = y_grid)

The estimated bandwidth from this function can be used as bandwidth input to lpcde directly by using the option bwselect in lpcde to specify bandwidth selection type instead of running lpbwcde first. R methods like summary, print and coef can be applied to the objects returned by lpbwcde for understanding the output.

Additional replication scripts showcasing the full functionality of the package along with references for a full description of the methods along with theoretical guarantees can be found on the GitHub repository lpcde.

References

Software and Implementation

  • Cattaneo, Chandak, Jansson and Ma (2025):

lpcde: Estimation and Inference for Local Polynomial Conditional Density Estimators JOSS, forthcoming.

Technical and Methodological

  • Cattaneo, Chandak, Jansson and Ma (2024):

Boundary Adaptive Local Polynomial Conditional Density Estimators Bernoulli 30(4): 3193-3223.

Copy Link

Version

Install

install.packages('lpcde')

Monthly Downloads

343

Version

0.1.6

License

GPL (>= 3)

Maintainer

Rajita Chandak

Last Published

February 25th, 2025

Functions in lpcde (0.1.6)

c_exact

C matrix Internal Function
confint.lpcde

Confint method for local polynomial density conditional estimation
fhat

Estimator construction
lpbwcde

Data-driven bandwidth selection for local polynomial conditional density estimators
S_x

Sx Matrix (Internal Function)
kernel_eval

Kernel Evaluation function (Internal Function)
basis_vec

Unit basis vector
cov_hat

cov_hat: covariance estimator
c_x

c_x vector (Internal Function)
bw_irot

IROT Bandwidth selection
plot.lpcde

Plot method for local polynomial density conditional estimation
coef.lpbwcde

Coef method for local polynomial density bandwidth selection
coef.lpcde

Coef method for local polynomial density conditional estimation
check_inv

Matrix invertibility check
mvec

Polynomial order vector
poly_base

Polynomial basis vector expansion
print.lpbwcde

Print method for local polynomial conditional density bandwidth selection
normal_dgps

Internal function.
lpcde

Local polynomial conditional density estimation
int_val

Lp integral (Internal Function)
print_all_sumC

All Sums in C++ (Internal Function)
lpcde_fn

lpcde_fn: Conditional density estimator.
summary.lpbwcde

Summary method for local polynomial conditional density bandwidth selection
print.lpcde

Print method for local polynomial conditional density estimation
summary.lpcde

Summary method for local polynomial density conditional estimation
vcov.lpcde

Variance-Covariance
T_y_exact

T matrix Internal Function Generate Matrix
S_exact

S matrix Internal Function
T_y

T_y matrix (Internal Function)
b_x

bx
bw_rot

ROT Bandwidth selection
T_x

T_x matrix (Internal Function)