WhitenSVD {REPPlab} | R Documentation |
Whitening Data Using Singular Value Decomposition
Description
The function whitens a data matrix using the singular value decomposition.
Usage
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 |
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
Examples
# 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)