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 = "Schennach",
  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 specifying the method to automatically determine the xi interval if xi_lb and xi_ub are NULL. Options are "Schennach" and "Schennach_loose". If "Schennach" the range is selected based on the Theorem 2 in Schennach2020, if "Schennach_loose", it is defined by the initial interval given in Theorem 2 without selecting the xi_n.

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 <- rnorm(100)
fit <- biasBound_density(X = X, x = 1, h = 0.09)
#> Warning: No feasible xi_n passed Schennach's test in interval [0.9556, 3.0220]. Using theoretical upper bound xi_ub = 3.0220. This may indicate insufficient signal or inappropriate xi bounds.
print(fit)
#> Bias-Bounded Density Estimation
#> 
#> Call:
#> biasBound_density(X = X, x = 1, h = 0.09)
#> 
#> Sample size: n = 100
#> Bandwidth:   h = 0.0900 (user-specified) 
#> Kernel:      Schennach2004 
#> 
#> Bias bound parameters:
#>   A = 0.7387, r = 2.4307
#>   bias bound b1x = 0.0055
#> 
#> Point estimate at x = 1.0000: f(x) = 0.1577
#> Confidence level: 95%
#> 
#> Use summary() for detailed statistics
#> Use plot() to visualize results
coef(fit)
#>         A         r         h 
#> 0.7386753 2.4307402 0.0900000 

# Example 2: Range estimation with automatic bandwidth
fit2 <- biasBound_density(X = X, h = NULL, h_method = "cv")
#> Warning: No feasible xi_n passed Schennach's test in interval [0.9556, 3.0220]. Using theoretical upper bound xi_ub = 3.0220. This may indicate insufficient signal or inappropriate xi bounds.
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):  100
#>   Bandwidth (h):    0.5481
#>   Kernel function:  Schennach2004
#> 
#> Bias Bound Parameters:
#>   A (amplitude):    0.7387
#>   r (decay rate):   2.4307
#>   b1x (bias bound): 0.0730
#>   Xi interval:      [0.9556, 3.0220]
#> 
#> Range Estimation:
#>   Density estimates:
#>    min Q1.25% median   mean Q3.75%    max 
#> 0.0000 0.0386 0.1510 0.1626 0.2874 0.3506 
#> 
#>   Standard errors:
#>    min   mean    max 
#> 0.0000 0.0256 0.0429 
#> 
# }