Re: [R] combining variables with PCA

From: Dave Roberts <droberts_at_montana.edu>
Date: Thu 26 Jan 2006 - 03:02:32 EST

Christian,

     One of the arguments to prcomp() is retx, with a default value of TRUE. As explained in the help file, if retx is TRUE the prcomp object reurned by the function contains the projection of the original data along the principal components (which many of us call "scores"). Thus

 > z <- prcomp(cbind(runif(20),runif(20)))  > z$x

                PC1          PC2
  [1,] -0.176564769 -0.175010202
  [2,]  0.286746995 -0.464200150
  [3,] -0.010385993  0.415020704
  [4,]  0.002108131 -0.150929991
  [5,] -0.030974478  0.005799164
  [6,]  0.516400555  0.051731728
  [7,] -0.273545829  0.082611939

  [8,] 0.028956640 -0.095674198
  [9,] -0.343703128 0.148523268
[10,] -0.267409591  0.236258325
[11,] -0.362410088  0.278893388
[12,]  0.198170683 -0.282954098
[13,] -0.195901187  0.030789448
[14,]  0.544997090 -0.089702393
[15,] -0.361799979 -0.055526763
[16,]  0.117021002  0.362033198
[17,] -0.385818070 -0.459613063
[18,] -0.182413187 -0.218456938
[19,]  0.386595491  0.337704022
[20,]  0.509929714  0.042702611

You can use the columns of the x component of your prcomp object as the independent variable in your regression analysis or whatever.


David W. Roberts                                     office 406-994-4548
Professor and Head                                      FAX 406-994-3190
Department of Ecology                         email droberts@montana.edu
Montana State University
Bozeman, MT 59717-3460

Christian Jones wrote:
> hello R_team
>
> having perfomed a PCA on my fitted model with the function:
>
> data<- na.omit(dataset)
>
> data.pca<-prcomp(data,scale =TRUE),
>
> Ive decided to aggregate two variables that are highly correlated.
>
> My first question is:
>
> How can I combine the two variables into one new predictor?
>
> and secondly:
>
> How can I predict with the newly created variable in a new dataset?
>
> Guess I need the "predict" and "new data" command but Im having problems with the syntax and the help function was not sufficient on this issue.
>
> many thanks in advance
>
> Christian
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> 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

--

______________________________________________
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
Received on Thu Jan 26 03:34:21 2006

This archive was generated by hypermail 2.1.8 : Thu 26 Jan 2006 - 08:07:39 EST