dd_plot: Depth-Depth Plot

View source: R/dd_plot.R

dd_plotR Documentation

Depth-Depth Plot

Description

Computes and plots the depth-depth (DD) plot for two samples. Each observation from both samples is assigned two depth values — its depth with respect to the empirical distribution of x and its depth with respect to the empirical distribution of y. Points from the same distribution cluster near the main diagonal.

Usage

dd_plot(
  x,
  y,
  depth_fn = simplicial_depth,
  plot = TRUE,
  xlab = "Depth wrt X",
  ylab = "Depth wrt Y",
  main = "DD-Plot",
  col_x = "steelblue",
  col_y = "firebrick",
  pch_x = 19L,
  pch_y = 17L,
  legend = TRUE,
  ...
)

Arguments

x

Numeric matrix (n1 x d) — first sample.

y

Numeric matrix (n2 x d) — second sample. Must have the same number of columns as x.

depth_fn

Depth function to use. Must have signature f(x, data, ...). Defaults to simplicial_depth.

plot

Logical. If TRUE (default), produce the plot.

xlab

Label for the x-axis. Defaults to "Depth wrt X".

ylab

Label for the y-axis. Defaults to "Depth wrt Y".

main

Plot title. Defaults to "DD-Plot".

col_x

Color for points from x. Default "steelblue".

col_y

Color for points from y. Default "firebrick".

pch_x

Plot character for points from x. Default 19.

pch_y

Plot character for points from y. Default 17.

legend

Logical. If TRUE (default), add a legend.

...

Additional arguments passed to depth_fn.

Details

The DD-plot was introduced by Liu, Parelius & Singh (1999) as a nonparametric graphical tool for two-sample comparison. It is the multivariate analog of the QQ-plot, using depth in place of quantiles.

If the two distributions are identical, all points should fall near the diagonal. Systematic deviations indicate location shifts (points above or below the diagonal) or scale/shape differences (spread of points away from the diagonal).

Value

Invisibly returns a data frame with columns:

depth_x

Depth of each observation with respect to x.

depth_y

Depth of each observation with respect to y.

sample

Factor indicating which sample the observation came from.

References

Liu, R. Y., Parelius, J. M. & Singh, K. (1999). Multivariate analysis by data depth: descriptive statistics, graphics and inference. Annals of Statistics, 27(3), 783–858.

Examples


set.seed(42)
# Same distribution — points near diagonal
x <- matrix(rnorm(200), nrow = 100, ncol = 2)
y <- matrix(rnorm(200), nrow = 100, ncol = 2)
dd_plot(x, y, depth_fn = simplicial_depth)

# Location shift — points systematically off diagonal
y_shift <- matrix(rnorm(200, mean = 1), nrow = 100, ncol = 2)
dd_plot(x, y_shift, depth_fn = tukey_depth)

# Store results without plotting
result <- dd_plot(x, y, plot = FALSE)
head(result)



depthR documentation built on June 26, 2026, 5:07 p.m.