WhitenSVD: Whitening Data Using Singular Value Decomposition

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/whitenSVD.R

Description

The function whitens a data matrix using the singular value decomposition.

Usage

1
WhitenSVD(x, tol = 1e-06)

Arguments

x

A numeric data frame or data matrix with at least two rows.

tol

Tolerance value to decide the rank of the data. See details for further information. If set to NULL it will be ignored.

Details

The function whitens the data so that the result has mean zero and identity covariance matrix using the function svd. The data can have here less observations than variables and svd will determine the rank of the data automatically as the number of singular values larger than the largest singular value times tol. If tol=NULL the rank is set to the number of singular values, which is not advised when one or more singular values are close to zero.

The output contains among others as attributes the singular values and the matrix needed to backtransform the whitened data to its original space.

Value

The whitened data.

Author(s)

Klaus Nordhausen

See Also

svd, cov, colMeans

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# more observations than variables
X <- matrix(rnorm(200),ncol=4)
A <- WhitenSVD(X)
round(colMeans(A),4)
round(cov(A),4)
# how to backtransform
summary(sweep(A %*% (attr(A,"backtransform")), 2, attr(A,"center"), "+") - X)

# fewer observations than variables
Y <- cbind(rexp(4),runif(4),rnorm(4), runif(4), rnorm(4), rt(4,4))
B <- WhitenSVD(Y)
round(colMeans(B),4)
round(cov(B),4)
# how to backtransform
summary(sweep(B %*% (attr(B,"backtransform")), 2, attr(B,"center"), "+") - Y)

REPPlab documentation built on May 2, 2019, 8:58 a.m.