| mvscale | R Documentation |
A multivariate version of base::scale(), that takes account
of the covariance matrix of the data, and uses robust estimates
of center, scale and covariance by default.
The centers are removed using medians,
the scale function for univariate data is s_Qn,
the covariance matrix for multivariate data is estimated using a robust OGK estimate.
The data are scaled using the Cholesky decomposition of
the inverse (co)variance. Then the scaled data are returned.
Details of the methods are provided by Hyndman (2026).
mvscale(
object,
center = stats::median,
scale = robustbase::s_Qn,
cov = robustbase::covOGK,
warning = TRUE
)
object |
A vector, matrix, or data frame containing some numerical data. |
center |
A function to compute the center of each numerical variable. Set to NULL if no centering is required. |
scale |
A function to scale each numerical variable. When
|
cov |
A function to compute the covariance matrix. Set to NULL if no rotation required. |
warning |
Should a warning be issued if non-numeric columns are ignored? |
Optionally, the centering and scaling can be done for each variable
separately, so there is no rotation of the data, by setting cov = NULL.
Also optionally, non-robust methods can be used by specifying center = mean,
scale = stats::sd(), and cov = stats::cov(). Any non-numeric columns are retained
with a warning.
A vector, matrix or data frame of the same size and class as object,
but with numerical variables replaced by scaled versions.
Rob J Hyndman
Hyndman, R J (2026) "That's weird: Anomaly detection using R", Section 2.6, 3.6 and 3.7.
base::scale(), stats::sd(), stats::cov(), robustbase::covOGK(), robustbase::s_Qn()
# Univariate z-scores (no rotation)
z <- mvscale(faithful, center = mean, scale = sd, cov = NULL, warning = FALSE)
# Non-robust scaling with rotation
z <- mvscale(faithful, center = mean, cov = stats::cov, warning = FALSE)
# Robust scaling and rotation
z <- mvscale(faithful, warning = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.