Skip to contents

Estimate a univariate density and construct pointwise confidence intervals that include an estimated upper bound on smoothing bias.

Usage

bias_bound_density(
  x,
  eval = NULL,
  bw = "cv",
  conf_level = 0.95,
  kernel = c("schennach", "sinc", "normal", "epanechnikov"),
  control = NULL
)

Arguments

x

Numeric sample.

eval

Optional numeric evaluation points. When NULL, a regular grid is constructed from the sample.

bw

Either a positive numeric bandwidth or one of "cv" and "silverman" for automatic selection. "silverman" uses the stats::bw.nrd0() normal-reference rule, multiplied by 2.34 for the Epanechnikov kernel or by a heuristic 1.2 for either infinite-order kernel; the normal-kernel factor is unchanged.

conf_level

Confidence level in (0, 1).

kernel

One of "schennach", "sinc", "normal", or "epanechnikov". The formal coverage result in Schennach (2020) assumes an infinite-order kernel whose Fourier transform equals one near the origin; "schennach" is the recommended theorem-compatible default.

control

Optional named list of advanced settings. Supported entries are resolution (evaluation-grid size), frequency_window ("snr", "schennach", or "schennach_loose"), frequency_range (a positive, increasing vector of length two), noise_floor ("auto", "compact", or "general"), envelope_use_y (fit the regression numerator envelope to the response-weighted Fourier transform), smoothness_floor (enforce the theoretical integer restriction \(r \in \{2,3,\ldots\}\)), smoothness_max (largest exponent considered; default 50), approximate_kernel, kernel_resolution, and envelope_points_per_log. The "snr" frequency rule is a finite-sample heuristic; "schennach" is the exact Theorem 2 rule and errors with guidance when its feasible set is empty. The last setting replaces the formerly hard-coded 200-point log-frequency resolution.

Value

An object of class bbnp_density. Standard methods include print(), summary(), plot(), coef(), and confint().

Examples

set.seed(123)
x <- runif(200) + runif(200)
fit <- bias_bound_density(x, bw = "silverman")
fit
#> Bias-Bounded Density Estimation
#> 
#> Call:
#> bias_bound_density(x = x, bw = "silverman")
#> 
#> Sample size: n = 200
#> Bandwidth:   h = 0.1463 (automatic: silverman) 
#> Kernel:      Schennach2004 
#> 
#> Bias bound parameters:
#>   A = 4.3453, r = 2.0000
#>   bias bound b1x = 0.2081
#> 
#> Evaluation points: 100 (range: [-0.0695, 2.0688])
#> Confidence level: 95%
#> 
#> Use summary() for detailed statistics
#> Use plot() to visualize results
confint(fit)
#>              lower     upper
#>   [1,] 0.000000000 0.2444963
#>   [2,] 0.000000000 0.2577139
#>   [3,] 0.000000000 0.2715213
#>   [4,] 0.000000000 0.2860707
#>   [5,] 0.000000000 0.3014864
#>   [6,] 0.000000000 0.3179500
#>   [7,] 0.000000000 0.3352951
#>   [8,] 0.000000000 0.3535992
#>   [9,] 0.000000000 0.3727311
#>  [10,] 0.000000000 0.3928861
#>  [11,] 0.000000000 0.4138548
#>  [12,] 0.000000000 0.4357032
#>  [13,] 0.000000000 0.4582127
#>  [14,] 0.000000000 0.4815420
#>  [15,] 0.000000000 0.5055576
#>  [16,] 0.000000000 0.5302320
#>  [17,] 0.000000000 0.5553568
#>  [18,] 0.000000000 0.5810607
#>  [19,] 0.000000000 0.6073014
#>  [20,] 0.000000000 0.6339094
#>  [21,] 0.018086502 0.6607493
#>  [22,] 0.037625295 0.6879566
#>  [23,] 0.057626999 0.7155100
#>  [24,] 0.077936678 0.7432117
#>  [25,] 0.098420950 0.7708984
#>  [26,] 0.119223838 0.7987806
#>  [27,] 0.140252820 0.8267468
#>  [28,] 0.161438494 0.8547182
#>  [29,] 0.182580558 0.8824454
#>  [30,] 0.203860788 0.9101804
#>  [31,] 0.225096004 0.9376961
#>  [32,] 0.246335281 0.9650681
#>  [33,] 0.267318960 0.9919744
#>  [34,] 0.288192177 1.0186131
#>  [35,] 0.308760680 1.0447477
#>  [36,] 0.329088246 1.0704703
#>  [37,] 0.348933229 1.0954862
#>  [38,] 0.368295388 1.1198070
#>  [39,] 0.387115991 1.1433695
#>  [40,] 0.405357880 1.1661376
#>  [41,] 0.422795451 1.1878402
#>  [42,] 0.439328393 1.2083637
#>  [43,] 0.455009741 1.2277838
#>  [44,] 0.469732938 1.2459779
#>  [45,] 0.483256997 1.2626575
#>  [46,] 0.495456628 1.2776777
#>  [47,] 0.506400221 1.2911309
#>  [48,] 0.516021775 1.3029434
#>  [49,] 0.524022452 1.3127549
#>  [50,] 0.530390306 1.3205571
#>  [51,] 0.535073001 1.3262906
#>  [52,] 0.538110812 1.3300084
#>  [53,] 0.539204480 1.3313465
#>  [54,] 0.538477670 1.3304573
#>  [55,] 0.535769551 1.3271432
#>  [56,] 0.531208227 1.3215588
#>  [57,] 0.524605913 1.3134700
#>  [58,] 0.516085200 1.3030212
#>  [59,] 0.505566177 1.2901063
#>  [60,] 0.493185678 1.2748835
#>  [61,] 0.478941725 1.2573387
#>  [62,] 0.462853057 1.2374808
#>  [63,] 0.445013079 1.2154088
#>  [64,] 0.425575990 1.1912955
#>  [65,] 0.404682130 1.1652954
#>  [66,] 0.382290542 1.1373354
#>  [67,] 0.358599499 1.1076384
#>  [68,] 0.333825374 1.0764502
#>  [69,] 0.308151185 1.0439749
#>  [70,] 0.281580030 1.0101877
#>  [71,] 0.254322792 0.9753256
#>  [72,] 0.226652788 0.9397073
#>  [73,] 0.198679418 0.9034427
#>  [74,] 0.170562731 0.8667064
#>  [75,] 0.142462032 0.8296729
#>  [76,] 0.114648785 0.7926678
#>  [77,] 0.087146367 0.7556895
#>  [78,] 0.060205489 0.7190417
#>  [79,] 0.033948960 0.6828604
#>  [80,] 0.008545088 0.6473475
#>  [81,] 0.000000000 0.6125700
#>  [82,] 0.000000000 0.5787516
#>  [83,] 0.000000000 0.5459796
#>  [84,] 0.000000000 0.5143510
#>  [85,] 0.000000000 0.4840198
#>  [86,] 0.000000000 0.4550432
#>  [87,] 0.000000000 0.4274758
#>  [88,] 0.000000000 0.4012819
#>  [89,] 0.000000000 0.3766730
#>  [90,] 0.000000000 0.3535731
#>  [91,] 0.000000000 0.3319680
#>  [92,] 0.000000000 0.3117534
#>  [93,] 0.000000000 0.2930375
#>  [94,] 0.000000000 0.2756381
#>  [95,] 0.000000000 0.2593815
#>  [96,] 0.000000000 0.2440110
#>  [97,] 0.000000000 0.2288043
#>  [98,] 0.000000000 0.2080858
#>  [99,] 0.000000000 0.2080858
#> [100,] 0.000000000 0.2080858