Learn R Programming

mrfDepth (version 1.0.1)

depthContour: Depth contours of multivariate data

Description

Computes the vertices of depth contours of multivariate data (in at least two dimensions). The contours can be computed based on halfspace depth, projection depth or skewness-adjusted 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 with $p \ge 2$.
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. Available options are "hdepth" for halfspace depth, "projdepth" for projection depth and "sprojdepth" for skewness-adjusted projection depth.
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 or sprojdepth. 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$.

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.

Details

Depth contours of level $\alpha$ 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 defaults a random set of $250*p$ 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 invariant.

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.

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

Run this code
# Compute the depth contours of a simple
# two-dimensional dataset. 
data(cardata90)
Result <- depthContour(x = cardata90,
                       alpha = c(0.125,0.25),
                       type = "hdepth")
plotContours(x = cardata90, depthContour = Result)

# One may consider different depths such as 
# e.g. projection depth by changing the type.
Result <- depthContour(x = cardata90,
                       alpha = c(0.125,0.25),
                       type = "projdepth")
plotContours(x = cardata90, depthContour = Result)
# When there is skewness in the data projection depth
# is less appropriate. 

# For projection based types the directions to 
# search intersections may be specified by the user. 
# It is advised to consider enough to directions to have
# a good image of the depth contours. 
directions <- matrix(c(0,1,
                       1,1,
                       1,0,
                       -1,-1),
                     ncol = 2, byrow = TRUE)
Result <- depthContour(x = cardata90,
                       alpha = c(0.125,0.25),
                       type = "sprojdepth",
                       directions = directions
                       )
plot <- plotContours(x = cardata90, depthContour = Result)
plot
# Note that plot seems distorted as the axis are 
# not on the same range. The returned object is a ggplot2
# object that may be edited using standard ggplot2 commands.
plot + ylab("Engine displacement") + xlab("Weight in pounds")


# Options for the underlying routine may be passed using 
# the options argument.
Result <- depthContour(x = cardata90,
                       alpha = c(0.125,0.25, 0.35),
                       type = "sprojdepth",
                       options = list(type = "Affine",
                                      seed = 123)
                      )
plotContours(x = cardata90, depthContour = Result)
# The number of steps in the bisection algorithm is
# controlled by the \code{max.iter} argument. Setting
# this too low may lead to bad approximations of the
# contour. 
Result <- depthContour(x = cardata90,
                       alpha = c(0.125,0.25, 0.35),
                       type = "sprojdepth",
                       options = list(type = "Affine",
                                      seed = 123,
                                      max.iter = 2)
                      )
plotContours(x = cardata90, depthContour = Result)
# One can check the algorithm hasn't converged on any 
# direction for contour level 0.125. 
Result[[1]]$depth
sum(Result[[1]]$converged)

Run the code above in your browser using DataLab