whitening (version 1.1.1)

whiteningMatrix: Compute Whitening Matrix and Whiten Data

Description

whiteningMatrix computes the whitening matrix W corresponding to the five natural whitening procedures discussed in Kessy, Lewin, and Strimmer (2018).

whiten whitens data X using the empirical covariance matrix \(cov(X)\) as basis for computing the whitening transformation.

Usage

whiteningMatrix(Sigma, method=c("ZCA", "PCA", "Cholesky",
                                "ZCA-cor", "PCA-cor"))
whiten(X, center=FALSE, method=c("ZCA", "PCA", "Cholesky", "ZCA-cor", "PCA-cor"))

Arguments

Sigma

Covariance matrix.

method

Determines the type of whitening.

X

Data matrix, with samples in rows and variables in columns.

center

Center columns to mean zero.

Value

whiteningMatrix returns a square whitening matrix W.

whiten returns the whitened data matrix \(Z = X W'\).

Details

ZCA whitening, or Mahalanobis whitening ensures that the average covariance between whitened and orginal variables is maximal. Likewise, ZCA-cor whitening leads to whitened variables that are maximally correlated (on average) with the original variables.

In contrast, PCA and PCA-cor whitening lead to maximally compressed whitened variables, as measured by squared covariance and correlation, respectively.

Cholesky whitening is the unique whitening procedure that results from lower-triangular positive diagonal cross-covariance and cross-correlations matrices.

In PCA and PCA-cor eigenvector matrices with positive diagonal are used, in order to resolve the sign-ambiguity and also to make cross-correlations and cross-correlations positive diagonal.

For details see Kessy, Lewin, and Strimmer (2018).

ZCA-cor whitening is implicitely employed in computing CAT and CAR scores (cf. catscore and carscore).

Canonical correlation analysis (CCA) can also be understood as a special form form of whitening.

References

Kessy, A., A. Lewin, and K. Strimmer. 2018. Optimal whitening and decorrelation. The American Statistician. 72: 309-314. https://doi.org/10.1080/00031305.2016.1277159

See Also

catscore and carscore.

Examples

Run this code
# NOT RUN {
# load whitening library
library("whitening")

######

# example data set
# E. Anderson. 1935.  The irises of the Gaspe Peninsula.
# Bull. Am. Iris Soc. 59: 2--5
data("iris")
X = as.matrix(iris[,1:4])
d = ncol(X) # 4
n = nrow(X) # 150
colnames(X) # "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"

# estimate covariance
S = cov(X)

# ZCA-cor whitening matrix
W.ZCAcor = whiteningMatrix(S, method="ZCA-cor")

# whitened data
Z.ZCAcor.1 = tcrossprod(X, W.ZCAcor) 
zapsmall( cov(Z.ZCAcor.1) )

# directly compute whitened data from X
Z.ZCAcor.2 = whiten(X, method="ZCA-cor")
zapsmall( cov(Z.ZCAcor.2) )
# }

Run the code above in your browser using DataLab