Recover data from principal component analysis
Recover data from principal component analysis based on the first (typically few) components.
recover_pca_data(object, comp = 1)
object
: An object of class prcomp
.comp
: The number of components to be used. Must be smaller than the number of variables.A dataframe
crime <- doBy::crimeRate rownames(crime) <- crime$state crime$state <- NULL o <- order(apply(scale(crime), 1, sum)) dat <- crime[o,] head(dat) tail(dat) matplot(scale(dat), type="l") pc1 <- prcomp(dat, scale. = TRUE) summary(pc1) rec2 <- recover_pca_data(pc1, 2) pairs(rec2) par(mfrow=c(1,2)) matplot(scale(dat), type="l") matplot(scale(rec2), type="l") j <- merge(dat, rec2, by=0) pairs(j[,-1])