kde_1d | R Documentation |
A pure R implementation of an approximate one-dimensional KDE, similar
to density
but using a different algorithm not involving
fft
. Two extra facilities are provided, namely
(a) the kernel may be given either as a character string to select one of a
number of kernel functions provided, or a user defined R function, and (b) the
kde may be fitted beyond the prescribed limits for the result, and folded back
to emulate the effect of having known bounds for the distribution.
kde_1d( x, bw = bw.nrd0, kernel = c("gaussian", "biweight", "cosine", "epanechnikov", "logistic", "optCosine", "rectangular", "squaredCosine", "triangular", "tricube", "triweight", "uniform"), n = 512, limits = c(rx[1] - cut * bw, rx[2] + cut * bw), cut = 3, na.rm = FALSE, adjust = 1, fold = FALSE, ... ) ## S3 method for class 'kde_1d' print(x, ...) ## S3 method for class 'kde_1d' plot( x, ..., col = "steel blue", las = 1, xlab = bquote(x == italic(.(x$data_name))), ylab = expression(kde(italic(x))) )
x |
A numeric vector for which the kde is required or (in methods)
an object of class |
bw |
The bandwidth or the bandwidth function. |
kernel |
The kernel function, specified either as a character string or as an R function. Partial matching of the character string is allowed. |
n |
Integer, the number of equally-spaced values in the abscissa of the kde |
limits |
numeric vector of length 2. Prescribed x-range limits for the x-range of the result. May be infinite, but infinite values will be pruned back to an appropriate value as determined by the data. |
cut |
The number of bandwidths beyond the range of the input x-values to use |
na.rm |
Logical value: should any missing values in x be silently removed? |
adjust |
numeric value: a multiplier to be applied to the computed bandwidth. |
fold |
Logical value: should the kde be estimated beyond the prescribed limits for the result and 'folded back' to emulate the effect of having known range boundaries for the underlying distribution? |
... |
currently ignored, except in method functions |
las, col, xlab, ylab |
base graphics parameters |
A list of results specifying the result of the kde computation, of class "kde_1d"
set.seed(1234) u <- runif(5000) kdeu0 <- kde_1d(u, limits = c(-Inf, Inf)) kdeu1 <- kde_1d(u, limits = 0:1, kernel = "epan", fold = TRUE) plot(kdeu0, col = 4) lines(kdeu1, col = "dark green") fun <- function(x) (0 < x & x < 1) + 0 curve(fun, add=TRUE, col = "grey", n = 1000)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.