Learn R Programming

depth (version 2.0-0)

isodepth: Contour plots for depth functions

Description

Draws a contour plot of Tukey's depth function.

Usage

isodepth(x, dpth = NULL, output = FALSE, twodim = TRUE, mustdith = FALSE, maxdith = 50, dithfactor = 10, trace.errors = TRUE, eps = 1e-8, factor = 0.8, xlab = "X", ylab = "Y", zlab = "Tukey's depth", colcontours = NULL, ...)

Arguments

x
Bivariate data as a matrix, data frame or list. If it is a matrix or data frame, then each row is viewed as one bivariate observation. If it is a list, both components must be numerical vectors of equal length (coordinates of observations).
dpth
Vector of positive integers. Numbers $1,2,\ldots$ refer to contours of depth $1/n, 2/n,\ldots$, where $n$ is the number of observations. Useful to draw particular contours. Default dpth = NULL corresponds to the set of all contours.
output
Logical. Default FALSE produces a contour plot; otherwise a list of contour vertices.
twodim
Logical. twodim = FALSE returns a transparent perspective plot making use of the rgl package.
mustdith
Logical. Should dithering be applied? Used when data set is not in general position or a numerical problem is encountered.
maxdith
Positive integer. Maximum number of dithering steps.
dithfactor
Scaling factor used for horizontal and vertical dithering.
trace.errors
Logical. Should all contours be considered? Used when a numerical problem is encountered for some inner contours. Default trace.errors = FALSE means those contours are left out.
eps
Error tolerance to control the calculation.
factor
Proportion (0 to 1) of outermost contours computed according to a version of the algorithm ISODEPTH of Rousseeuw and Ruts (1998); remaining contours are derived from an algorithm in Rousseeuw et al. (1999).
xlab
Title for x-axis. Must be a character string.
ylab
Title for y-axis. Must be a character string.
zlab
Title for z-axis. Used jointly with twodim = FALSE.
colcontours
Vector of color names of some or all of the contours. Recycling is used when necessary. Colors can be specified in different ways, see color specification in par,
...
Any additional graphical parameters (see par).

Value

output = FALSE yields a contour plot. If not, the function returns a list of $m$ components, where $m$ is the number of contours and component $i$ is a matrix whose rows are the vertices of contour $i$.

Details

Tukey's depth and dimension 2 only. Contours are computed according to algorithm ISODEPTH by Ruts and Rousseeuw (1996) or, more exactly, revised versions of this algorithm which appear in Rousseeuw and Ruts (1998) and Rousseeuw et al. (1999). Argument factor determines which version to use. If $n$ is the number of observations, contours of depth $\le$ factor $n/2$ are obtained from the 1998 version, while the remaining contours are derived from the 1999 version.

When the data set is not in general position, dithering can be used in the sense that random noise is added to each component of each observation. Random noise takes the form eps times dithfactor times U for the horizontal component and eps times dithfactor times V for the vertical component, where U, V are independent uniform on [-.5, 5.]. This is done in a number of consecutive steps applying independent U's and V's.

References

Ruts, I. and Rousseeuw, P.J. (1996), Computing depth contours of bivariate point clouds, Comput. Stat. Data An., 23, 153--168.

Rousseeuw, P.J. and Ruts, I. (1998), Constructing the bivariate Tukey median, Stat. Sinica, 8, 828--839.

Rousseeuw, P.J., Ruts, I., and Tukey, J.W. (1999), The Bagplot: A Bivariate Boxplot, The Am. Stat., 53, 382--387.

See Also

depth, perspdepth

Examples

Run this code
## exact contour plot with 10 contours
set.seed(601) ; x = matrix(rnorm(48), nc = 2)
isodepth(x)

## exact colored contours
set.seed(159); library(MASS)
mu1 <- c(0,0); mu2 <- c(6,0); sigma <- matrix(c(1,0,0,1), nc = 2)
mixbivnorm <- rbind(mvrnorm(80, mu1 ,sigma), mvrnorm(20, mu2, sigma))
isodepth(mixbivnorm, dpth = c(35,5), col = rainbow(2))

## vertices of each contour
set.seed(601)
x <- matrix(rnorm(48), nc = 2)
isodepth(x, output = TRUE)

## data set not in general position
data(starsCYG, package = "robustbase")
isodepth(starsCYG, mustdith = TRUE)

## colored contours
set.seed(601)
x <- matrix(rnorm(48), nc = 2)
isodepth(x, colcontours= rainbow(10))

# perspective plot
library(rgl)
set.seed(601)
x <- matrix(rnorm(48), nc = 2)
isodepth(x, twodim = FALSE)

Run the code above in your browser using DataLab