Contour functions
contour.RdContour levels and sizes.
Usage
contourLevels(x, ...)
# S3 method for class 'kde'
contourLevels (x, prob, cont, approx=TRUE, ...)
# S3 method for class 'kda'
contourLevels (x, prob, cont, approx=TRUE, ...)
# S3 method for class 'kdde'
contourLevels(x, prob, cont, approx=TRUE, which.deriv.ind=1, ...)
contourSizes(x, abs.cont, cont=c(25,50,75), approx=TRUE)
contourProbs(x, abs.cont, cont=c(25,50,75), approx=TRUE)
contourBreaks(x, n=3, cont=c(25,50,75), type="density")Arguments
- x
object of class
kde,kddeorkda- 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
- approx
flag to compute approximate contour levels. Default is TRUE.
- which.deriv.ind
partial derivative index. Default is 1.
- ...
other parameters
- type
type of contour levels: one of
"density", "length", "quantile", "natural". Default is "density".- n
number of contour levels for
type="length", "natural". Default is 3.
Value
–For contourLevels/contourBreaks, for kde objects, returns a vector of heights. For kda objects, returns a list of vectors, one for each training group. For kdde objects, returns a matrix, one row for each partial derivative.
–For contourSizes, returns an approximation of the Lebesgue measure of the level set, i.e. length (d=1), area (d=2), volume (d=3), hyper-volume (d>4).
–For contourProbs, returns an approximation of the probability measure of the level set.
Details
–For contourLevels, the most straightforward is to specify prob.
The heights of the corresponding highest density region with probability prob are
computed. The cont parameter here is consistent with
cont parameter from plot.kde, plot.kdde, and plot.kda
i.e. cont=(1-prob)*100%.
If both prob and cont are missing then a pretty set of
nlevels contours are computed. From ks \(\geq\) 1.15.0, nlevels=5 always.
–For contourSizes, the length, area, volume etc. and for contourProbs,
the probability, are approximated by Riemann sums. These are rough approximations and
depend highly on resolution of the estimation grid, and so should be interpreted carefully.
If approx=FALSE, then the exact KDE is computed. Otherwise
it is interpolated from an existing KDE grid: this can dramatically
reduce computation time for large data sets.
–For contourBreaks, different contour level selection methods are available, including equal length ("length"), quantile ("quantile") and natural breaks/Jenks ("natural") for density estimates only. The default contourBreaks(type="density") is equivalent to contourLevels.
Examples
set.seed(8192)
x <- rmvnorm.mixt(n=1000, mus=c(0,0), Sigmas=diag(2), props=1)
fhat <- kde(x=x, binned=TRUE)
contourLevels(fhat, cont=c(25,50,75))
#> 75% 50% 25%
#> 0.11138323 0.08385792 0.04370685
contourProbs(fhat, abs.cont=contourLevels(fhat, cont=50))
#> 50%
#> 0.4601889
## compare approx prob with target prob=0.5
contourSizes(fhat, cont=25, approx=TRUE)
#> 75%
#> 1.850091
## compare to approx circle of radius=0.75 with area=1.77
contourBreaks(fhat, n=3, type="natural")
#> [1] 0.002129676 0.041174642 0.104037824
## natural or Jenks contour levels