[R] PCA

Paul Johnson pauljohn32 at gmail.com
Wed Mar 10 23:53:34 CET 2010


On Wed, Mar 10, 2010 at 4:42 PM, Xanthe Walker <xanthe.walker at gmail.com> wrote:
> Hello,
>
> I am trying to complete a PCA on a set of standardized ring widths from 8
> different sites (T10, T9, T8, T7, T6, T5, T3, and T2).
> The following is a small portion of my data:
>
> T10 T9 T8 T7 T6 T5 T3 T2 1.33738 0.92669 0.91146 0.98922 0.9308 0.88201
> 0.92287 0.91775 0.82181 1.05319 0.92908 0.97971 0.95165 0.98029 1.14048
> 0.77803 0.88294 0.96413 0.90893 0.87957 0.9961 0.74926 0.71394 0.70877
> 1.07549 1.13311 1.23536 1.19382 1.2362 1.07741 1.20334 0.8727 0.77737
> 0.99292 0.92703 1.02384 0.99831 1.1317 0.93672 1.07909 0.88933 1.15587
> 1.20885 0.8983 1.06476 0.81845 1.09017 0.72909 0.75347 0.95826 0.90922
> 0.73869 0.74846 0.70481 0.49826 0.91824 1.39082 1.1281 1.05147 0.95839
> 1.20648 1.24587 0.65045 1.23251 0.80977 0.89714 0.90042 0.9543 0.86217
> 1.20818 0.82725 0.7666 1.11092 1.10328 1.16464 1.00707 1.09575 1.04647
> 0.79045 0.47331 0.88753 1.04699 1.0854 0.91803 1.03622 0.80624 0.905 1.28271
> 0.91963 0.90121 0.89136 0.97408 1.0449 1.00572 0.7703 1.48373 1.31837
> 0.97733 1.04229 1.23096 1.14002 1.09911 0.77523 1.31543
>
> This is what I have done in R:
>
> rm(list=ls(all=TRUE))
> PCA<-read.csv("PCAsites.csv", header=TRUE)
> PCA
> attach(PCA)
> names(PCA)
>
> ###using correlation matrix#####
>
> p1 <- princomp(PCA, cor = TRUE)
> summary(p1)
> loadings(p1)
> plot(p1)
> biplot(p1)
> p1$scores
> screeplot(p1, npcs=4, type="lines")
>
> The problem is that the purpose of this analysis is to derive a new data
> set, using the first component, that I can work with. In other words, I am
> doing this to compress the data into one column of ring widths. How do I
> derive a new data set?
>

the output of p1$scores is what you want, isn't it?  Or just one column of it?

desiredScores <- p1$scores[ , 1]

p



-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas



More information about the R-help mailing list