| kdensity | R Documentation |
kdensity computes a parametrically guided kernel density estimate
for univariate data. It supports asymmetric kernels and parametric starts
through the kernel and start arguments.
kdensity(
x,
bw = NULL,
adjust = 1,
kernel = NULL,
start = NULL,
support = NULL,
na.rm = FALSE,
normalized = TRUE,
tolerance = 0.01
)
x |
Numeric vector containing the data. |
bw |
A bandwidth function. Can be either a string, a custom-made
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 built-in
kernels or be custom-made. See |
start |
Parametric start. Can be chosen from the list of built-in
parametric starts or be custom-made. 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 '$':
xThe data supplied in x.
bw_str, bw, adjust, hThe bandwidth function, the resulting
bandwidth, the adjust argument, and the adjusted
bandwidth.
kernel_str, kernel, start, start_str, supportName 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, normalizedName 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.
callThe call to kdensity.
estimatesNamed numeric vector containing the parameter estimates from the parametric start.
logLikThe log-likelihood 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): 882-904.
Jones, M. C., and D. A. Henderson. "Miscellanea kernel-type density estimation on the unit interval." Biometrika 94.4 (2007): 977-984.
Chen, Song Xi. "Probability density function estimation using gamma kernels." Annals of the Institute of Statistical Mathematics 52.3 (2000): 471-480.
Silverman, Bernard W. Density estimation for statistics and data analysis. Vol. 26. CRC press, 1986.
The stats package function stats::density().
## 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.