Description Usage Arguments Details Value References See Also Examples
kdensity
computes a parametrically guided kernel density estimate
for univariate data. It supports asymmetric kernels and parametric starts
through the kernel
and start
arguments.
1 2 3 4 5 6 7 8 9 10 11 
x 
Numeric vector containing the data. 
bw 
A bandwidth function. Can be either a string, a custommade
function, or a double. The supported bandwidth functions are documented
in 
adjust 
An adjustment constant, so that 
kernel 
The kernel function. Can be chosen from the list of builtin
kernels or be custommade. See 
start 
Parametric start. Can be chosen from the list of builtin
parametric starts or be custommade. See 
support 
The support of the data. Must be compatible with the supplied

na.rm 
Logical; if 
normalized 
Logical; if 
tolerance 
Numeric; the relative error to tolerate in normalization. 
The default values for bw
, kernel
, start
, and
support
are interdependent, and are chosen to make sense. E.g.,
the default value for support
when start = beta
is
c(0, 1)
.
The start
argument defaults to uniform
, which corresponds
to ordinary kernel density estimation. The typical default value for
kernel
is gaussian
.
If normalized
is FALSE
and start != "uniform"
, the resulting
density will not integrate to 1 in general.
kdensity
returns an S3 function object of
base::class()
"kdensity". This is a callable function with the
following elements, accessible by '$':
x
The data supplied in x
.
bw_str, bw, adjust, h
The bandwidth function, the resulting
bandwidth, the adjust
argument, and the adjusted
bandwidth.
kernel_str, kernel, start, start_str, support
Name of the kernel, the kernel object, name of the parametric start, the start object, and the support of the density.
data.name, n, range, has.na, na.rm, normalized
Name of the data, number of
observations, the range of the data, whether the data
x
contained NA
values, whether na.rm is TRUE
or not, and whether the density is normalized.
call
The call
to kdensity
.
estimates
Named numeric vector containing the parameter estimates from the parametric start.
logLik
The loglikelihood of the parametric starts. Is NA
for the uniform start.
Hjort, Nils Lid, and Ingrid K. Glad. "Nonparametric density estimation with a parametric start." The Annals of Statistics (1995): 882904.
Jones, M. C., and D. A. Henderson. "Miscellanea kerneltype density estimation on the unit interval." Biometrika 94.4 (2007): 977984.
Chen, Song Xi. "Probability density function estimation using gamma kernels." Annals of the Institute of Statistical Mathematics 52.3 (2000): 471480.
Silverman, Bernard W. Density estimation for statistics and data analysis. Vol. 26. CRC press, 1986.
The stats
package function stats::density()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  ## Use gamma kernels to model positive data, the concentration of
## theophylline
concentration = Theoph$conc + 0.001
plot(kdensity(concentration, start = "gamma", kernel = "gamma", adjust = 1/3),
ylim = c(0, 0.15), lwd = 2, main = "Concentration of theophylline")
lines(kdensity(concentration, start = "gamma", kernel = "gaussian"),
lty = 2, col = "grey", lwd = 2)
lines(kdensity(concentration, start = "gaussian", kernel = "gaussian"),
lty = 3, col = "blue", lwd = 2)
lines(kdensity(concentration, start = "gaussian", kernel = "gamma", adjust = 1/3),
lty = 4, col = "red", lwd = 2)
rug(concentration)
## Using a density and and estimator from another package.
skew_hyperbolic = list(
density = SkewHyperbolic::dskewhyp,
estimator = function(x) SkewHyperbolic::skewhypFit(x, printOut = FALSE)$param,
support = c(Inf, Inf)
)
kde = kdensity(diff(LakeHuron), start = skew_hyperbolic)
plot(kde, lwd = 2, col = "blue",
main = "Annual differences in water level (ft) of Lake Huron, 1875  1972")
lines(kde, plot_start = TRUE, lty = 2, lwd = 2) # Plots the skew hyperbolic density.
rug(diff(LakeHuron))
kde$estimates # Also: coef(kde)
# Displays the parameter estimates:
# mu delta beta nu
# 1.140713 3.301112 2.551657 26.462469

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.