depthContour: Depth contours of multivariate data

View source: R/depthContour.R

depthContourR Documentation

Depth contours of multivariate data

Description

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.

Usage

depthContour(x, alpha = NULL, type = "hdepth", directions = NULL, options = NULL)

Arguments

x

An n by p data matrix.

alpha

A vector containing the depth values of which the depth contours have to be computed.

type

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.

directions

An m by p matrix specifying the directions on which to compute the vertices (see Details).

options

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 100.

Details

Depth contours of level \alpha (or \alpha-depth contours) are the boundaries of depth regions. Depth regions of level \alpha are defined as regions in space containing the multivariate points whose depth value is at least \alpha.

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 250p directions is considered. On each direction a point is searched having depth \alpha. Starting limits are obtained by projecting the data on the direction and considering the data point with univariate depth \alpha. By definition the multivariate depth of this point has to be lower or equal to \alpha. A second limit is obtained by considering the deepest location estimate. The maximum number of iterations bisecting the current search interval can be specified through the options argument 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 p. If so, the routine will give a warning, giving back the dimension of the subspace together with a direction describing a hyperplane containing this subspace.

Value

The output consists of a list. Each element of the list contains the following elements for each value \alpha specified in the argument alpha.

depth

The depth of the depth contour of level \alpha. For halfspace depth this is equal to floor(\alpha n)/n. For projection depth, skewness-adjusted projection depth and directional depth, this equals to \alpha.

vertices

The coordinates of the vertices of the depth contour.

empty

Logical indicating whether the corresponding depth region is empty.
FALSE indicates the depth region is non-empty.
TRUE indicates the depth region is empty.

dithered

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.

converged

A vector of length m containing a flag indicating for each direction whether convergence was reached by the bisecting algorithm within the allowed max.iter number of steps.

type

Same as input parameter type.

dimension

If the data are lying in a lower dimensional subspace, the dimension of this subspace.

hyperplane

If the data are lying in a lower dimensional subspace, a direction orthogonal to this subspace.

Author(s)

P. Segaert based on Fortran code by P.J. Rousseeuw, I. Ruts and A. Struyf

References

Ruts I., Rousseeuw P.J. (1996). Computing depth contours of bivariate point clouds. Computational Statistics & Data Analysis, 23, 153–168.

See Also

plotContours, bagdistance

Examples


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


mrfDepth documentation built on May 29, 2024, 5:04 a.m.