Construct an xDensity representation of a kernel smoothing estimator.

kernelXD(x, n = 512, from, to, mean, sd, any0 = FALSE, ...)

Arguments

x

Vector of samples from the underlying distribution.

n, from, to

Optional arguments to density which are used to set the grid on which to evaluate the kernel estimator.

mean, sd

Optional mean and standard deviation arguments for the extended density. Default to the mean and standard deviation of x.

any0

Logical; if FALSE forces the support of the density to be the real line.

...

Additional arguments to density.

Value

An xDensity object.

Examples

# xDensity approximation to a noncentral-t distribution # true parameters lambda <- rnorm(1) # noncentrality parameter nu <- runif(1, 4, 6) # degrees of freedom # simulate data x <- rt(1e4, df = nu, ncp = lambda) # xDensity approximation xDens <- kernelXD(x)
#> Warning: Endpoint matching failed. mean/sd set to empirical estimates.
# true vs approximate PDF curve(dt(x, df = nu, ncp = lambda), from = min(x), to = max(x), ylab = "Density")
curve(dXD(x, xDens = xDens), add = TRUE, col = "red")
legend("topleft", legend = c("True PDF", "xDensity Approx."), fill = c("black", "red"))