prcompRecon: prcomp object reconstruction

View source: R/prcompRecon.R

prcompReconR Documentation

prcomp object reconstruction

Description

This function reconstructs the original field from an EOF object of the function prcomp.

Usage

prcompRecon(pca, pcs = NULL)

Arguments

pca

An object resulting from the function prcomp.

pcs

The principal components ("PCs") to use in the reconstruction (defaults to the full set of PCs: pcs=seq(pca$sdev)))

Examples

# prcomp
P <- prcomp(iris[,1:4])

# Full reconstruction
R <- prcompRecon(P)
plot(as.matrix(iris[,1:4]), R, xlab="original data", ylab="reconstructed data")
abline(0, 1, col=2)

# Partial reconstruction
RMSE <- NaN*seq(P$sdev)
for(i in seq(RMSE)){
  Ri <- prcompRecon(P, pcs=seq(i))
  RMSE[i] <- sqrt(mean((as.matrix(iris[,1:4]) - Ri)^2))
}
plot(RMSE, t="o", xlab="Number of pcs")
abline(h=0, lty=2)


marchtaylor/sinkr documentation built on July 4, 2022, 5:48 p.m.