[R] questions about principle component analysis (princomp)

Thomas Petzoldt petzoldt at rcs.urz.tu-dresden.de
Thu Jul 22 08:29:37 CEST 2004


Yunfeng Hu wrote:
> Hi, I am a new R user and am currently using princomp to conduct a PCA. 
> I have read the help(princomp) and still do not quite understand 
> everything in the help. Basically I want to get the covariance matrix, 
> and eigenvector/eigenvalues (loadings()?) so that I can find the 
> principle components. Thanks!

Hello,

you may start with the examples at the bottom of the help page to get 
more understanding. Here is a modified version of that example:

  data(USArrests)
  pc<- princomp(USArrests)

  summary(pc)
  loadings(pc)

  plot(pc)
  biplot(pc)

# some other useful methods mentioned on the help page:

  cov(USArrests)          # covariance matrix
  eigen(cov(USArrests))   # eigenvalues/vector

# and a way to show, what things are stored in pc

  str(pc)

# so they can be extracted as shown on the help page.

# Please note, that the scaled version (correlation matrix)
# would be more appropriate there, e.g.

  pc<- princomp(USArrests, cor=TRUE)
  summary(pc)
  cor(USArrests)
  eigen(cor(USArrests))


Hope it helps

Thomas P.




More information about the R-help mailing list