View source: R/biloop_transform.R
| biloop_transform | R Documentation |
Apply the biloop transformation to a numeric vector or matrix.
biloop_transform(
X,
c1 = 4,
c2 = 4,
do_scale = FALSE,
location = NULL,
scale = NULL
)
X |
A numeric vector or matrix. Rows correspond to observations and columns to variables. |
c1 |
Positive scaling constant used before the hyperbolic tangent transformation. See details. |
c2 |
Positive scaling constant applied to the first transformed coordinate. See details. |
do_scale |
Logical; if |
location |
Optional centering vector used when |
scale |
Optional scaling vector used when |
The transformation maps each univariate variable to a two-dimensional
nonlinear embedding x \mapsto (u(x), v(x)) based on two tangential circles.
The data may first be robustly standardized (advised).
For multivariate input, the transformation is applied columnwise and the
transformed columns are concatenated.
u(x) and v(x) are defined as:
u(x) =
\begin{cases}
c_2(1 + \cos(2\pi \tanh(x/c_1) + \pi)), & x \ge 0 \\
-c_2(1 + \cos(2\pi \tanh(x/c_1) - \pi)), & x < 0
\end{cases}
v(x) = \sin(2\pi \tanh(x/c_1))
By default, no scaling is performed. If do_scale = TRUE and neither
location nor scale is supplied, the columns are centered using
stats::median() and scaled using stats::mad(). Alternatively,
user-supplied location and scale vectors can be provided.
The biloop transformation can be useful when computing dependence measures on heavy-tailed or contaminated data.
A numeric matrix with nrow(X) rows and 2 * ncol(X)
columns. If X is a vector, the result has two columns.
Leyder, S., Raymaekers, J., and Rousseeuw, P. J. (2026). Robust Distance Covariance. International Statistical Review, 94, 1–25. doi:10.1111/insr.70005
x <- rnorm(10)
biloop_transform(x)
X <- cbind(rnorm(10), rt(10, df = 3))
colnames(X) <- c("A","B")
biloop_transform(X, do_scale = TRUE)
# Robust scaling using median and Qn from robustbase
if (requireNamespace("robustbase", quietly = TRUE)) {
loc <- apply(X, 2, median)
scl <- apply(X, 2, robustbase::Qn)
biloop_transform(X, do_scale = TRUE, location = loc, scale = scl)
}
# Robust distance correlation after the biloop transformation
if (requireNamespace("robustbase", quietly = TRUE) &&
requireNamespace("energy", quietly = TRUE)) {
x <- rt(100, df = 3)
y <- x^2 + rnorm(100, sd = 0.2)
loc_x <- median(x)
scl_x <- robustbase::Qn(x)
loc_y <- median(y)
scl_y <- robustbase::Qn(y)
xb <- biloop_transform(x, do_scale = TRUE, location = loc_x, scale = scl_x)
yb <- biloop_transform(y, do_scale = TRUE, location = loc_y, scale = scl_y)
energy::dcor(xb, yb)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.