
Computes the vertices of depth contours of multivariate data. The contours can be
computed based on halfspace depth, projection depth, skewness-adjusted projection
depth or directional projection depth. To make the actual plot for bivariate data,
the function plotContours
needs to be called on the result of depthContour
.
depthContour(x, alpha = NULL, type = "hdepth", directions = NULL, options = NULL)
The output consists of a list. Each element of the list contains the following elements for each value alpha
.
The depth of the depth contour of level
The coordinates of the vertices of the depth contour.
Logical indicating whether the corresponding depth region is empty.
FALSE
indicates the depth region is non-empty.
TRUE
indicates the depth region is empty.
Logical indicating whether dithering has been applied in the exact bivariate algorithm based on halfspace depth.
FALSE
indicates no dithering has been applied.
TRUE
indicates dithering has been applied.
A vector of length max.iter
number of steps.
Same as input parameter type.
If the data are lying in a lower dimensional subspace, the dimension of this subspace.
If the data are lying in a lower dimensional subspace, a direction orthogonal to this subspace.
An
A vector containing the depth values of which the depth contours have to be computed.
The depth used in the computation of the contours:
hdepth
for halfspace depth, projdepth
for projection depth,
sprojdepth
for skewness-adjusted projection depth and
dprojdepth
for directional projection depth.
Defaults to hdepth
.
An
A list of options to pass to hdepth
, projdepth
,
sprojdepth
or dprojdepth
.
In addition the following option may be specified:
max.iter
The maximum number of iterations in the bisection algorithm used
to compute the depth contour corresponding to level alpha.
Defaults to
P. Segaert based on Fortran code by P.J. Rousseeuw, I. Ruts and A. Struyf
Depth contours of level
For bivariate data halfspace depth contours can be computed exactly following the algorithm in Ruts and Rousseeuw (1996). When the data are not in general position (i.e. when there is a line containing more than two observations) dithering is performed by adding random Gaussian noise to the data.
In all other cases an approximated method is performed using a bisection algorithm. Intersections with the depth contours are searched on lines originating from the depth median. The user can specify a set of directions corresponding to these lines. By default a random set of max.iter
. Note that this method is only affine or rotation equivariant if the chosen directions are affine or rotation equivariant.
It is first checked whether the data is found to lie in a subspace of
dimension lower than
Ruts I., Rousseeuw P.J. (1996). Computing depth contours of bivariate point clouds. Computational Statistics & Data Analysis, 23, 153--168.
plotContours
, bagdistance
# Compute and plot some halfspace depth contours of a two-dimensional dataset.
# The returned object is a ggplot2 object that may be edited
# using standard ggplot2 commands.
# One may consider different depth functions such as projection depth
# by changing the input parameter 'type'.
# By default the halfspace depth is used.
data(bloodfat)
Result <- depthContour(x = bloodfat,
alpha = c(0.03, 0.125, 0.25))
plotContours(x = bloodfat, depthContour = Result)
# Other options are projection depth, skewness-adjusted projection depth
# and directional projection depth
# they can be used by specifying type to be
# "projdepth", "sprojdepth" or "dprojdepth" respectively.
# When there is skewness in the data projection depth
# is less appropriate.
Result <- depthContour(x = bloodfat,
alpha = c(0.25, 0.35, 0.45),
type = "projdepth")
plotContours(x = bloodfat, depthContour = Result)
# The skewness-adjusted projection depth and directional projection depth
# better reflect the skewness in the data.
Result <- depthContour(x = bloodfat,
alpha = c(0.35, 0.45, 0.55),
type = "sprojdepth")
plotContours(x = bloodfat, depthContour = Result)
Result <- depthContour(x = bloodfat,
alpha = c(0.25, 0.35, 0.45),
type = "dprojdepth")
plotContours(x = bloodfat, depthContour = Result)
Run the code above in your browser using DataLab