lpbwcde {lpcde}R Documentation

Data-driven bandwidth selection for local polynomial conditional density estimators

Description

lpbwcde implements the bandwidth selection methods for local polynomial based conditionaldensity (and derivatives) estimation proposed and studied in (Cattaneo et al. 2024).

Companion command: lpcde for estimation and robust bias-corrected inference.

Related Stata and R packages useful for nonparametric estimation and inference are available at https://nppackages.github.io/.

Usage

lpbwcde(
  y_data,
  x_data,
  x,
  y_grid = NULL,
  p = NULL,
  q = NULL,
  grid_spacing = "",
  ng = NULL,
  mu = NULL,
  nu = NULL,
  kernel_type = c("epanechnikov", "triangular", "uniform"),
  bw_type = c("mse-rot", "imse-rot"),
  regularize = NULL
)

Arguments

y_data

Numeric matrix/data frame, the raw data of independent.

x_data

Numeric matrix/data frame, the raw data of covariates.

x

Numeric, specifies the evaluation point in the x-direction. Default is median of the dataset.

y_grid

Numeric, specifies the grid of evaluation points. When set to default, grid points will be chosen as 0.05-0.95 percentiles of the data, with a step size of 0.05.

p

Nonnegative integer, specifies the order of the local polynomial for Y used to construct point estimates. (Default is 2.)

q

Nonnegative integer, specifies the order of the local polynomial for X used to construct point estimates. (Default is 1.)

grid_spacing

String, If equal to "quantile" will generate quantile-spaced grid evaluation points, otherwise will generate equally spaced points.

ng

Int, number of grid points to be used in generating bandwidth estimates.

mu

Nonnegative integer, specifies the derivative with respect to Y of the distribution function to be estimated. 0 for the distribution function, 1 (default) for the density funtion, etc.

nu

Nonnegative integer, specifies the derivative with respect to X of the distribution function to be estimated.

kernel_type

String, specifies the kernel function, should be one of "triangular", "uniform" or "epanechnikov".

bw_type

String, specifies the method for data-driven bandwidth selection. This option will be ignored if bw is provided. Implementable with "mse-rot" (default, mean squared error-optimal bandwidth selected for each grid point)

regularize

Boolean (default TRUE). Option to regularize bandwidth selection to have atleast 20+max(p, q)+1 datapoints when evaluating the estimator.

Value

BW

A matrix containing (1) y_grid (grid point), (2) bw (bandwidth)

opt

A list containing options passed to the function.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu.

Rajita Chandak (maintainer), Princeton University. rchandak@princeton.edu.

Michael Jansson, University of California Berkeley. mjansson@econ.berkeley.edu.

Xinwei Ma, University of California San Diego. x1ma@ucsd.edu.

References

Cattaneo MD, Chandak R, Jansson M, Ma X (2024). “Local Polynomial Conditional Density Estimators.” Bernoulli.

See Also

Supported methods: coef.lpbwcde, print.lpbwcde, summary.lpbwcde.

Examples

# Generate a random sample
set.seed(42);
x_data = rnorm(2000)
y_data = rnorm(2000, mean=x_data)
x = 0

# Construct bandwidth
bw1 <- lpbwcde(y_data = y_data, x_data = x_data, x=x, bw_type = "mse-rot")
summary(bw1)

# Display bandwidths for a subset of y_grid points
summary(bw1, y_grid=bw1$BW[2:5, "y_grid"])


[Package lpcde version 0.1.4 Index]