Skip to contents

Estimates the density at a given point or across a range, and provides visualization options for density, bias, and confidence intervals.

Usage

biasBound_density(
  X,
  x = NULL,
  h = NULL,
  h_method = "cv",
  alpha = 0.05,
  resol = 100,
  xi_lb = NULL,
  xi_ub = NULL,
  methods_get_xi = "snr",
  noise_floor = "auto",
  envelope_use_Y = TRUE,
  integer_r = TRUE,
  ora_Ar = NULL,
  kernel.fun = "Schennach2004",
  if_approx_kernel = TRUE,
  kernel.resol = 1000
)

Arguments

X

A numerical vector of sample data.

x

Optional. A scalar or range of points where the density is estimated. If NULL, a range is automatically generated.

h

A scalar bandwidth parameter. If NULL, the bandwidth is automatically selected using the method specified in 'h_method'.

h_method

Method for automatic bandwidth selection when h is NULL. Options are "cv" (cross-validation) and "silverman" (Silverman's rule of thumb). Default is "cv".

alpha

Confidence level for intervals. Default is 0.05.

resol

Resolution for the estimation range. Default is 100.

xi_lb

Optional. Lower bound for the interval of Fourier Transform frequency xi. Used for determining the range over which A and r is estimated. If NULL, it is automatically determined based on the methods_get_xi.

xi_ub

Optional. Upper bound for the interval of Fourier Transform frequency xi. Similar to xi_lb, it defines the upper range for A and r estimation. If NULL, the upper bound is determined based on the methods_get_xi.

methods_get_xi

A string selecting the frequency-window rule used when xi_lb/xi_ub are NULL: "snr" (default; a signal-to-noise cutoff that selects a valid window at realistic sample sizes), "Schennach" (the data-driven rule of Schennach 2020, Theorem 2), or "Schennach_loose" (the initial, un-refined interval).

noise_floor

Noise-floor form for the Schennach test: "auto" (default), "compact", or "general".

envelope_use_Y

If TRUE (default), fit the regression envelope to the cross-spectrum |phi_YX|; if FALSE, fit it to the marginal spectrum |phi_X|.

integer_r

If TRUE (default), clamp the fitted envelope slope up to r = 2 when it falls below the minimum smoothness assumed by Schennach (2020, Definition 2), i.e. r < 2, and refit A; this keeps the bias-bound integral finite. Slopes >= 2 are left unchanged.

ora_Ar

Optional list of oracle values for A and r (for research/comparison purposes).

kernel.fun

A string specifying the kernel function to be used. Options are "Schennach2004", "sinc", "normal", "epanechnikov".

if_approx_kernel

Logical. If TRUE, uses approximations for the kernel function.

kernel.resol

The resolution for kernel function approximation. See fun_approx.

Value

An object of class bbnp_density with components:

density

Density estimates (for range estimation)

x

Evaluation points

estimate

Point estimate (for single x)

conf_int

List containing lower, upper bounds and conf_level

bias_bound

List containing b1x, est_A, est_r, xi_interval

std_error

Standard errors

call

The function call

bandwidth

Bandwidth used

n

Sample size

kernel

Kernel type

data

Original data

Use plot(), summary(), coef(), and confint() methods to work with the result.

Examples

# \donttest{
# Example 1: Point estimation at x = 1
X <- gen_sample_data(size = 500, dgp = "2_fold_uniform", seed = 1)
fit <- biasBound_density(X = X, x = 1, h = 0.09)
print(fit)
#> Bias-Bounded Density Estimation
#> 
#> Call:
#> biasBound_density(X = X, x = 1, h = 0.09)
#> 
#> Sample size: n = 500
#> Bandwidth:   h = 0.0900 (user-specified) 
#> Kernel:      Schennach2004 
#> 
#> Bias bound parameters:
#>   A = 5.7610, r = 2.3783
#>   bias bound b1x = 0.0504
#> 
#> Point estimate at x = 1.0000: f(x) = 0.8767
#> Confidence level: 95%
#> 
#> Use summary() for detailed statistics
#> Use plot() to visualize results
coef(fit)
#>        A        r        h 
#> 5.761046 2.378286 0.090000 

# Example 2: Range estimation with automatic bandwidth
fit2 <- biasBound_density(X = X, h = NULL, h_method = "cv")
plot(fit2)           # Density plot

plot(fit2, type = "ft")  # Fourier transform plot

summary(fit2)
#> Summary: Bias-Bounded Density Estimation
#> ============================================================
#> 
#> Call:
#> biasBound_density(X = X, h = NULL, h_method = "cv")
#> 
#> Sample Information:
#>   Sample size (n):  500
#>   Bandwidth (h):    0.2603
#>   Kernel function:  Schennach2004
#> 
#> Bias Bound Parameters:
#>   A (amplitude):    5.7610
#>   r (decay rate):   2.3783
#>   b1x (bias bound): 0.2181
#>   Xi interval:      [2.3941, 4.3249]
#> 
#> Range Estimation:
#>   Density estimates:
#>    min Q1.25% median   mean Q3.75%    max 
#> 0.0201 0.1965 0.4630 0.4486 0.7088 0.8132 
#> 
#>   Standard errors:
#>    min   mean    max 
#> 0.0067 0.0296 0.0424 
#> 
# }