adaptive_fnhat {kader}R Documentation

Specialized “Workhorse” Function for Kernel Adaptive Density Estimators

Description

Common specialized computational “workhorse” function to compute the kernel adaptive density estimators both in eq. (1.6) of Srihera & Stute (2011) and in eq. (4) of Eichner & Stute (2013) (together with several related quantities) with a \sigma that minimizes the estimated MSE using an estimated \theta. This function is “specialized” in that it expects some pre-computed quantities (in addition to the point(s) at which the density is to be estimated, the data, etc.). In particular, the estimator of \theta (which is typically the arithmetic mean of the data) is expected to be already “contained” in those pre-computed quantities, which increases the computational efficiency.

Usage

adaptive_fnhat(x, data, K, h, sigma, Ai, Bj, fnx, ticker = FALSE,
  plot = FALSE, parlist = NULL, ...)

Arguments

x

Numeric vector (x_1, \ldots, x_k) of location(s) at which the density estimate is to be computed.

data

Numeric vector (X_1, \ldots, X_n) of the data from which the estimate is to be computed.

K

Kernel function with vectorized in- & output.

h

Numeric scalar, where (usually) h = n^{-1/5}.

sigma

Numeric vector (\sigma_1, \ldots, \sigma_s) with s \ge 1.

Ai

Numeric matrix expecting in its i-th row (x_i - X_1, \ldots, x_i - X_n)/h, where (usually) x_1, \ldots, x_k with k = length(x) are the points at which the density is to be estimated for the data X_1, \ldots, X_n with h = n^{-1/5}.

Bj

Numeric vector expecting (-J(1/n), \ldots, -J(n/n)) in case of the rank transformation method, but (\hat \theta - X_1, \ldots, \hat \theta - X_n) in case of the non-robust Srihera-Stute-method.

fnx

Numeric vector expecting (f_n(x_1), \ldots, f_n(x_k)) with f_n(x_i) the Parzen-Rosenblatt estimator at x_i, i.e., f_n(x_i) = mean(K(Ai[i,]))/h where here typically h = n^{-1/5}.

ticker

Logical; determines if a 'ticker' documents the iteration progress through sigma. Defaults to FALSE.

plot

Logical or character or numeric and indicates if graphical output should be produced. Defaults to FALSE (i.e., no graphical output is produced). If it is a character string or a numeric value, graphical output will be written to numbered pdf-files (one for each element of x, in the current working directory) whose names start with the provided “value” after converting it into a character string followed by the index number of the pertaining x-element. (Parts of the graphical output are generated by minimize_MSEHat.)

parlist

A list of graphical parameters; affects only the pdf-files (if any are created at all). Default: NULL.

...

Possible further arguments passed to minimize_MSEHat() (where they are currently ignored).

Details

The computational procedure in this function can be highly iterative because for each point in x (and hence for each row of matrix Ai) the MSE estimator is computed as a function of \sigma on a (usually fine) \sigma-grid provided through sigma. This happens by repeated calls to bias_AND_scaledvar(). The minimization in \sigma is then performed by minimize_MSEHat() using both a discrete grid-search and the numerical optimization routine implemented in base R's optimize(). Finally, compute_fnhat() yields the actual value of the density estimator for the adapted \sigma, i.e., for the MSE-estimator-minimizing \sigma. (If necessary the computation over the \sigma-grid is repeated after extending the range of the grid until the estimator functions for both bias and variance are not constant across the \sigma-grid.)

Value

A list of as many lists as elements in x, each with components x, y, sigma.adap, msehat.min, discr.min.smaller, and sig.range.adj whose meanings are as follows:

x the n coordinates of the points where the density is estimated.
y the estimate of the density value f(x).
sigma.adap Minimizer of MSE-estimator (from function minimize_MSEHat).
msehat.min Minimum of MSE-estimator (from function minimize_MSEHat).
discr.min.smaller TRUE iff the numerically found minimum was smaller than the discrete one (from function minimize_MSEHat).
sig.range.adj Number of adjustments of sigma-range.

References

Srihera & Stute (2011) and Eichner & Stute (2013): see kader.

Examples

## Not run: 
require(stats)

 # Kernel adaptive density estimators for simulated N(0,1)-data
 # computed on an x-grid using the rank transformation and the
 # non-robust method:
set.seed(2017);     n <- 100;     Xdata <- sort(rnorm(n))
x <- seq(-4, 4, by = 0.5);     Sigma <- seq(0.01, 10, length = 51)
h <- n^(-1/5)

x.X_h <- outer(x/h, Xdata/h, "-")
fnx <- rowMeans(dnorm(x.X_h)) / h   # Parzen-Rosenblatt estim. at
                                    # x_j, j = 1, ..., length(x).
 # non-robust method:
theta.X <- mean(Xdata) - Xdata
adaptive_fnhat(x = x, data = Xdata, K = dnorm, h = h, sigma = Sigma,
  Ai = x.X_h, Bj = theta.X, fnx = fnx, ticker = TRUE, plot = TRUE)

 # rank transformation-based method (requires sorted data):
negJ <- -J_admissible(1:n / n)   # rank trafo
adaptive_fnhat(x = x, data = Xdata, K = dnorm, h = h, sigma = Sigma,
  Ai = x.X_h, Bj = negJ, fnx = fnx, ticker = TRUE, plot = TRUE)

## End(Not run)


[Package kader version 0.0.8 Index]