PCA with Wuensch's beer data. http://core.ecu.edu/psyc/wuenschk/SPSS/SPSS-Data.htm library(psych) beer <- read.table("http://www.unt.edu/rss/class/mike/data/beer.txt",header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE) beer2 = beer[,1:7] #just the attribute variables beer2 fit <- principal(beer2, nfactors=3,rotate="varimax", scores=T) fit plot(fit) #Need R 2.8.1 fit$scores #VSS(beer2, rotate="varimax",n=5,pc = "pc") This function tries out several approaches to determine the best number of factors to retain. You will need an updated version of R to use it however. #Conceptual tie-in: PCA regression RegModel.1 <- lm(SES~ALCOHOL+AROMA+COLOR+COST+REPUTAT+SIZE+TASTE, data=beer) summary(RegModel.1) library(pls) beer.pcr <- pcr(SES ~ COST+SIZE+ALCOHOL+REPUTAT+AROMA+COLOR+TASTE, 3, data = beer) summary(beer.pcr) coef(beer.pcr, intercept=T) #coefs for original data loadings(beer.pcr) #only difference from above is this uses the covariance matrix. essentially it returns output from princomp function, and can be verified as below. loadingplot(beer.pcr, comps=1:3, legend="topleft") corrplot(beer.pcr, comps=1:3) #Doing it the hard way, PCA then lm for verification beer3=na.omit(beer) test=princomp(beer3[,1:7], scale=T) summary(test) test$loadings test$scores pcreg2=lm(beer3$SES~test$scores[,"Comp.1"]+test$scores[,"Comp.2"]+test$scores[,"Comp.3"]) summary(pcreg2) #Partial Least Squares beer.pls <- plsr(SES ~ COST+SIZE+ALCOHOL+REPUTAT+AROMA+COLOR+TASTE, 3, data = beer) summary(beer.pls) coef(beer.pls, intercept=T) #coefs for original data loadings(beer.pls) #only difference from above is this uses the covariance matrix. essentially it returns output from princomp function, and can be verified as below. loadingplot(beer.pls, comps=1:3, legend="topleft") corrplot(beer.pls, comps=1:3)