Learn R Programming

rmngb (version 0.6-1)

kde2dQuantile: Two-Dimensional Kernel Density Estimation Quantiles

Description

Produces sample quantiles from a two-dimensional kernel density estimation corresponding to the given probabilities.

Usage

kde2dQuantile(d, X, Y, probs = .05, ...)

Arguments

d
an object returnd by kde2d.
X
numeric vector of x coordinate of data whose sample quantiles are wanted.
Y
numeric vector of y coordinate of data whose sample quantiles are wanted.
probs
numeric vector of probabilities.
...
additional arguments passed to quantile.

Value

A vector of quantiles corresponding to the given probabilities.

Details

Useful for contour plots of 2-dimensional KDE quantiles.

See Also

kde2d, contour.

Examples

Run this code
a <- rnorm(10)
b <- rnorm(10)
# an ugly imitation of a kde2d estimate
# since we don't want to load MASS just for an exemple
f1 <- structure(list(x = c(-3.1, -1.575, -0.05, 1.475, 3),
                     y = c(-3.213, -1.591, 0.032, 1.654, 3.276),
                     z = structure(c(0, 0, 0.003, 0, 0, 0,
                                     0.009, 0.05, 0.015,
                                     0, 0.001, 0.05, 0.152,
                                     0.052, 0.003, 0, 0.01,
                                     0.039, 0.028, 0.001, 0,
                                     0, 0.001, 0, 0),
                                   .Dim = c(5L, 5L))),
                     .Names = c("x", "y", "z"))

quant <- kde2dQuantile(f1, a, b, c(.05, .5))

contour(f1, levels = quant, labels = names(quant))

Run the code above in your browser using DataLab