reconstructionError {EESPCA} | R Documentation |
Calculates the reduced rank reconstruction error
Description
Utility function for computing the squared Frobenius norm of the residual matrix formed by
subtracting from X
a reduced rank approximation of matrix X
generated from
the top k principal components contained in matrix V
.
Usage
reconstructionError(X,V,center=TRUE)
Arguments
X |
An n-by-p data matrix whose top k principal components are contained the p-by-k matrix |
V |
A p-by-k matrix containing the loadings for the top k principal components of |
center |
If true (the default), |
Value
The squared Frobenius norm of the residual matrix.
Examples
set.seed(1)
# Simulate 10x5 MVN data matrix
X=matrix(rnorm(50), nrow=10)
# Perform PCA
prcomp.out = prcomp(X)
# Get rank 2 reconstruction error, which will be the minimum since the first 2 PCs are used
reconstructionError(X, prcomp.out$rotation[,1:2])
# Use all PCs to get approximately 0 reconstruction error
reconstructionError(X, prcomp.out$rotation)
[Package EESPCA version 0.7.0 Index]