Learn R Programming

ks (version 1.7.0)

contourLevels: Contour levels for kde and kda.kde objects

Description

Contour levels for kde and kda.kde objects.

Usage

contourLevels(x, ...)

## S3 method for class 'kde': contourLevels(x, prob, cont, nlevels=5, approx=FALSE, ...)

## S3 method for class 'kda.kde': contourLevels(x, prob, cont, nlevels=5, approx=FALSE, ...)

Arguments

x
an object of class kde or kda.kde
prob
vector of probabilities corresponding to highest density regions
cont
vector of percentages which correspond to the complement of prob
nlevels
number of pretty contour levels
approx
flag to compute approximate contour levels. Default is FALSE.
...
other parameters

Value

  • For kde objects, returns vector of heights. For kda.kde objects, returns a list of vectors, one for each training group.

Details

The most straightforward is to specify prob. Heights of the corresponding highest density region with probability prob are computed. The cont parameter here is consistent with cont parameter from plot.kde and plot.kda.kde i.e. cont=(1-prob)*100%. If both prob and cont are missing then a pretty set of nlevels contours are computed.

If approx=FALSE, then the exact KDE at $x$ is computed. Otherwise the exact KDE is replaced by the weighted sum of the KDE at the nearest grid points. This can dramatically reduce computation time for large data sets.

See Also

contour, contourLines

Examples

Run this code
## kde 
x <- rmvnorm.mixt(n=100, mus=c(0,0), Sigmas=diag(2), props=1)
Hx <- Hpi(x)
fhatx <- kde(x=x, H=Hx)
lev1 <- contourLevels(fhatx, prob=c(0.25, 0.5, 0.75))
lev2 <- contourLevels(fhatx, cont=c(75, 50, 25))      ## lev1 == lev2

## kda.kde
library(MASS)
data(iris)
ir <- iris[,1]
ir.gr <- iris[,5]
kda.fhat <- kda.kde(ir, ir.gr, hs=sqrt(c(0.01, 0.04, 0.07)))
contourLevels(kda.fhat, prob=c(0.25, 0.5, 0.75))

Run the code above in your browser using DataLab