View source: R/ssMRCD_methods.R
| residuals.ssMRCD | R Documentation |
Computes group-wise Mahalanobis residuals (standardized distances) using the robust local covariance and location estimates from an ssMRCD object. Residuals can be computed for the fitted data or for new data, and optionally summarized as a trimmed mean.
## S3 method for class 'ssMRCD'
residuals(object, ...)
object |
An object of class |
... |
Additional arguments, see Details. |
The function supports several modes of use, controlled by the type argument in ...:
type"residuals" (default), "trimmed_mean", or "additional_data".
XA numeric matrix of new observations to compute residuals for. Required if type = "additional_data".
groupsA vector of group assignments for the new data in X. Required if type = "additional_data".
alphaA numeric value (default taken from the ssMRCD object if missing) indicating the quantile for trimmed mean calculation. Only used if type = "trimmed_mean".
Notes:
If type = "residuals", residuals are computed for the original data stored
in the ssMRCD object.
If type = "additional_data", both X and groups must be
provided. All residuals of X are returned (i.e., alpha = 1 is used internally).
If type = "trimmed_mean", the mean of the alpha proportion of
smallest residual norms is returned. This is also used for parameter tuning.
Depending on the type:
"residuals" or "additional_data"A numeric matrix of residuals.
"trimmed_mean"A single numeric value: the trimmed mean of residual norms.
ssMRCD
# Create data
x1 <- matrix(runif(200), ncol = 2)
x2 <- matrix(rnorm(200), ncol = 2)
x <- list(x1, x2)
# Define neighborhood weights
W <- matrix(c(0, 1, 1, 0), ncol = 2)
# Compute ssMRCD
localCovs <- ssMRCD(x, weights = W, lambda = 0.5)
# Residuals for original data (all)
head(residuals(localCovs, type = "residuals"))
# Trimmed mean of residual norms
residuals(localCovs, type = "trimmed_mean", alpha = 0.8)
# Residuals for new data
newX <- matrix(rnorm(20), ncol = 2, nrow = 10)
newGroups <- rep(2, 10)
residuals(localCovs, type = "additional_data", X = newX, groups = newGroups)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.