scale.ssMRCD: Locally Center and/or Scale or Data Using an ssMRCD Object

View source: R/ssMRCD_methods.R

scale.ssMRCDR Documentation

Locally Center and/or Scale or Data Using an ssMRCD Object

Description

Applies local standardization (scaling and/or centering) of either the original data from an ssMRCD object or new data provided via the X argument, using group-wise robust means and variances from the ssMRCD estimation.

Usage

## S3 method for class 'ssMRCD'
scale(x, ...)

Arguments

x

An object of class "ssMRCD". See ssMRCD.

...

List of additional arguments including:

X

A numeric matrix or data frame containing new observations to be scaled. If not provided, the data stored in the ssMRCD object is used.

groups

An integer vector from 1 to number of groups of group assignments corresponding to the rows of X. If X is not provided, defaults to the group assignments used in the original ssMRCD estimation.

center_only

Logical. If TRUE, only centering is applied; if FALSE, both centering and scaling are applied. Default is FALSE.

Details

For each group, the function applies scaling (or just centering) using the robust location and scale (square root of the diagonal of the covariance) estimates obtained during ssMRCD estimation.

Value

A numeric matrix of the same dimension as X, where each observation has been standardized (or centered) using the corresponding group-wise robust mean and (if applicable) variance from the ssMRCD model. If X = NULL, the original data from the ssMRCD object is returned in scaled form, sorted according to group labels.

See Also

ssMRCD

Examples

# Simulated example
x1 <- matrix(runif(200), ncol = 2)
x2 <- matrix(rnorm(200), ncol = 2)
x <- list(x1, x2)

W <- matrix(c(0, 1, 1, 0), ncol = 2)
localCovs <- ssMRCD(x, weights = W, lambda = 0.5)

# Scale original data
sc = scale(localCovs)

# Scale new observations
sc = scale(localCovs,
           list(X = matrix(rnorm(20), ncol = 2, nrow = 10),
           groups = rep(2, 10)))

# Center only
sc = scale(localCovs,
           list(X = matrix(rnorm(20), ncol = 2, nrow = 10),
           groups = rep(2, 10),
           center_only = TRUE))


ssMRCD documentation built on Nov. 5, 2025, 7:44 p.m.