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_condExpectation(
  Y,
  X,
  x = NULL,
  h = NULL,
  h_method = "cv",
  alpha = 0.05,
  est_Ar = NULL,
  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

Y

A numerical vector of sample data.

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.

est_Ar

Optional list of estimates for A and r. If NULL, they are computed using get_est_Ar().

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_regression with components:

fitted_values

\(E[Y|X=x]\) estimates (for range estimation)

x

Evaluation points

estimate

Point estimate (for single x)

conf_int

List containing lower, upper bounds and conf_level. Note that the confidence interval can be unbounded (i.e., contain -Inf or Inf) in regions where the estimated marginal density \(\hat f(x)\) is very close to zero, because the estimator is formed as a ratio involving \(1/\hat f(x)\).

bias_bound

List containing b1x, byx, est_A, est_r, est_B, xi_interval

std_error

Standard errors

marginal_density

f(x) estimates

joint_density

f_YX estimates

call

The function call

bandwidth

Bandwidth used

n

Sample size

kernel

Kernel type

data

Original data (X, Y)

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

Examples

# \donttest{
# Example 1: Point estimation at x = 1
X <- rnorm(100)
Y <- X^2 + rnorm(100)
fit <- biasBound_condExpectation(Y = Y, X = X, x = 1, h = 0.09)
#> Warning: No feasible xi_n passed Schennach's test in interval [0.9602, 3.0365]. Using theoretical upper bound xi_ub = 3.0365. This may indicate insufficient signal or inappropriate xi bounds.
print(fit)
#> Bias-Bounded Conditional Expectation Estimation
#> 
#> Call:
#> biasBound_condExpectation(Y = Y, X = X, x = 1, h = 0.09)
#> 
#> Sample size: n = 100
#> Bandwidth:   h = 0.0900 (user-specified) 
#> Kernel:      Schennach2004 
#> 
#> Bias bound parameters:
#>   A = 0.6037, r = 1.0221, B = 1.5601
#>   bias bounds: b1x = 1.5057, byx = 1.5057
#> 
#> Point estimate at x = 1.0000: E[Y|X=x] = 0.7576
#> Confidence level: 95%
#> 
#> Use summary() for detailed statistics
#> Use plot() to visualize results
#> Use fitted() to extract fitted values
fitted(fit)
#> [1] 0.7575995

# Example 2: Range estimation with plots
fit2 <- biasBound_condExpectation(Y = Y, X = X, h = NULL, h_method = "cv")
#> Warning: No feasible xi_n passed Schennach's test in interval [0.9602, 3.0365]. Using theoretical upper bound xi_ub = 3.0365. This may indicate insufficient signal or inappropriate xi bounds.
plot(fit2)              # Regression plot

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

summary(fit2)
#> Summary: Bias-Bounded Conditional Expectation Estimation
#> ============================================================
#> 
#> Call:
#> biasBound_condExpectation(Y = Y, X = X, h = NULL, h_method = "cv")
#> 
#> Sample Information:
#>   Sample size (n):  100
#>   Bandwidth (h):    0.5086
#>   Kernel function:  Schennach2004
#> 
#> Bias Bound Parameters:
#>   A (amplitude):    0.6037
#>   r (decay rate):   1.0221
#>   B (Y bound):      1.5601
#>   b1x (bias f(x)):  1.8274
#>   byx (bias f_YX):  1.8274
#>   Xi interval:      [0.9602, 3.0365]
#> 
#> Range Estimation:
#>   Fitted values (E[Y|X]):
#>      min   Q1.25%   median     mean   Q3.75%      max 
#> -81.4574   0.4563   1.1964   5.3030   4.3112 312.5747 
#> 
#>   Marginal density f(x):
#>     min    mean     max 
#> -0.0056  0.1818  0.3908 
#> 
#>   Standard errors:
#>    min   mean    max 
#> 0.0000 0.1045 0.3787 
#> 
# }