Hi Bjørn-Helge,

        Thanks for your help.

        In my case, there are more variables in the matrix than the units, 
so I have to use Prcomp with covariance to do PCA. The problem I am facing 
is how to get fisrt 8 coefficients and scores and how to write the result 
into text file. Thanks again.

        When I change princomp to prcomp below, I will NULL for pc$scores 
& pc$loadings.

        X <- some matrix
        pc <- prcomp(X)
        pc$scores[,1:4]    # The four first score vectors
        pc$loadings[,1:4]  # The four first loadings


Best Regards,
WeiQiang Li




bhx2@mevik.net (Bjørn-Helge Mevik) 
Sent by: r-help-bounces@stat.math.ethz.ch
No Phone Info Available
02/25/2005 05:38 PM

To
r-help@stat.math.ethz.ch
cc

Subject
Re: [R] How to set up number of prin comp.






>         I am trying to use PrinComp to do principle component analysis. 
I 
> would like to know how to set the number of principle components.

I assume you mean the function princomp (case _does_ matter in R) in
package stats (which is loaded by default).  This function has no way
of specifying how many components to calculate; it always gives you
all components.  You have to select the components you want
afterwards.  See help(princomp) for details.  E.g.

X <- some matrix
pc <- princomp(X)
pc$scores[,1:4]    # The four first score vectors
pc$loadings[,1:4]  # The four first loadings

(The loadings can also be extracted with loadings(pc)[,1:4] .)

-- 
Bjørn-Helge Mevik

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html


	[[alternative HTML version deleted]]


