# NOT RUN {
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)
# }
Run the code above in your browser using DataLab