In a bagplot, the inner polygon, called the bag, is constructed using the Tukey depth. What is the intuition of Tukey depth and how is it calculated? A simple two-dimensional example with ten to twenty data points may be helpful. Further, how often is is Tukey depth utilised and what alternative methods are similar?

  • 1
    $\begingroup$ Not the question, but I have found convex hulls easier to explain and in practice just as useful. The convex hull is just the smallest convex polygon including all data points, where including means that points can be vertices of the polygon or inside it. Then you can take the convex hull of points inside the polygon, and so on. For mundane examples see statalist.org/forums/forum/general-stata-discussion/general/… $\endgroup$
    – Nick Cox
    Oct 2, 2022 at 9:53

1 Answer 1



A bagplot is a method in robust statistics for visualizing two- or three-dimensional statistical data, analogous to the one-dimensional box plot.

enter image description here

Construction of a Bagplot

The bagplot consists of three nested polygons, called the "bag", the "fence", and the "loop".

enter image description here

  • The inner polygon, called the bag, is constructed on the basis of Tukey depth, the smallest number of observations that can be contained by a half-plane that also contains a given point. It contains at most $50\%$ of the data points. For more refer to Functional bagplot

An asterisk symbol (*) near the center of the graph is used to mark the depth median, the point with the highest possible Tukey depth.

  • The outermost of the three polygons, called the fence is not drawn as part of the bagplot but is used to construct it. It is formed by inflating the bag by a certain factor (usually 3). Observations outside the fence are flagged as outliers.
  • The observations that are not marked as outliers are surrounded by a loop, the convex hull of the observations within the fence.

Tukey Depth

Tukey depth is also known as location depth or halfspace depth. The Tukey depth is a measure of the depth of a point in a fixed set of points.

Given a finite set $S$ of $n$ points and a point $p$ in $\mathbb{R}^d$, the Tukey depth of $p$ is defined as the minimum number of points of $S$ contained in any closed halfspace with $p$ on its boundary. An equivalent definition is the minimum number of points of $S$ contained in any halfspace which also contains $p$.

Many different algorithms have been developed to compute the Tukey depth of a point. This problem is equivalent to the $\textit{maximum feasible subsystem} ~\textrm{(MAX FS)}$ problem which is a long-standing problem and has been extensively studied.

Calculating Tukey Depth

Suppose points in $S$ are in general position (no $d+1$ points of $S\cup\{p\}$ lie on a common hyperplane), an upper bound on the Tukey depth of $p$ can be obtained by selecting any non-trivial vector $v\in\mathbb{R}^d$ and computing the Tukey depth of $p\cdot v$ in the one-dimensional point set

$$S\cdot v=\{x\cdot v:~x {\in} S\}.\tag 1$$ If $v$ is the inner-normal of the boundary of the halfspace $\hbar$ that defines the depth value of $p$, then

$$\mathrm{depth}(p,S)=\mathrm{depth}(p\cdot v,S\cdot v).\tag 2$$

In $\mathbb{R}^1$, we rank the points $S\cup\{p\}$ starting with $0$ from both ends to the median, then the depth of $p$ is its rank. More generally, given any $k$-flat $f$ orthogonal to the boundary of $\hbar$ we have

$\mathrm{depth}(p,S)=\mathrm{depth}(p\cdot f,S\cdot f),\tag 3$$

where $p\cdot f$ is the orthogonal projection of $p$ onto $f,$ and $S\cdot f$ is the orthogonal projection of $S$ onto $f.$

From this paper Absolute approximation of Tukey depth: Theory and experiments

Theorem 1

Let $S$ be a set of $n$ points in general position in $\mathbb{R}^d,~S^1$ be a subset of $d-1$ elements chosen at random and without replacement from $S, v$ be the vector perpendicular to the plane containing $S^1$ and another point $p$, $σ$ be an integer such that

$$0\leqslant\sigma\leqslant\left\lfloor\frac nd\right\rfloor-1.$$


$$\Pr{\{\mathrm{depth}(p\cdot v,S\cdot v)\leqslant\mathrm{depth}(p,S)+\sigma\}}\geqslant\frac{{\sigma+d-1}\choose{d-1}}{n\choose{d-1}}.$$

Under point/hyperplane duality, the selection of $v$ is equivalent to selecting a random vertex in an arrangement of hyperplanes in $d-1$ dimensions. This selection of $v$ approximates $\text{depth}(p, S)$ to within $\sigma$ provided that the vertex is contained in a particular pseudo-ball of radius $\sigma.$ Therefore the proof boils down to showing that the number of vertices of an arrangement in a pseudo-ball of radius $σ$ is sufficiently large. In particular, we show that the number of vertices in such a pseudo-ball is at least ${\sigma+d-1}\choose{d-1}.$

Calculating Tukey Depth in R

Rdocumentation - depth.halfspace to calculate Tukey Depth

# 3-dimensional normal distribution
data <- mvrnorm(200, rep(0, 3), 
                matrix(c(1, 0, 0,
                         0, 2, 0, 
                         0, 0, 1),
                nrow = 3))
x <- mvrnorm(10, rep(1, 3), 
             matrix(c(1, 0, 0,
                      0, 1, 0, 
                      0, 0, 1),
             nrow = 3))
# default - random Tukey depth
depths <- depth.halfspace(x, data)
cat("Depths: ", depths, "\n")

# default exact method - "recursive"
depths <- depth.halfspace(x, data, exact = TRUE)
cat("Depths: ", depths, "\n")

# method "line"
depths <- depth.halfspace(x, data, method = "line")
cat("Depths: ", depths, "\n")
# }
  • $\begingroup$ Please could you additionally clarify if the following is correct: The Tukey depth can contain at most 50% of the data (the maximum a Tukey depth could be), and the minimum it could be is presumably just the point itself (100 / n%)? Conceptually (so excluding efficient means of doing it) the bag points are calculated by finding the Tukey depth of all points, and then the n / 2 points with the greatest depth correspond exactly to the points in the bag? $\endgroup$ Jun 1, 2020 at 7:54
  • $\begingroup$ I hope this link answers your question. Page No 205, 31.2 Functional Bagplot $\endgroup$ Jun 1, 2020 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.