Learn R Programming

ks (version 1.8.11)

contourLevels: Contours for kde and kda.kde objects

Description

Contour levels and sizes 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, ...)

contourSizes(x, abs.cont, cont=c(25,50,75), 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
abs.cont
vector of absolute contour levels
nlevels
number of pretty contour levels
approx
flag to compute approximate contour levels. Default is FALSE.
...
other parameters

Value

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

    --For contourSizes, an approximation of the Lebesgue measure of level set, i.e. length (d=1), area (d=2), volume (d=3), hyper-volume (d>4).

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. The approximate Lebesgue measures are approximated by Riemann sums. Thsese are rough approximations and depend highly on the estimation grid, and so should be interpreted carefully.

See Also

contour, contourLines

Examples

Run this code
## contourLevels 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

## contourLevels 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))

## contourSizes kde
x <- rmvnorm.mixt(n=1000, mus=c(0,0), Sigmas=diag(2), props=1)
Hx <- Hpi(x, binned=TRUE)
fhat <- kde(x=x, H=Hx, binned=TRUE)
plot(fhat, cont=25, xlim=c(-1,1), ylim=c(-1,1), asp=1) 
contourSizes(fhat, cont=25, approx=TRUE) 
 ## compare to approx circle of radius=0.75, vol=pi*0.75^2=1.767146

Run the code above in your browser using DataLab