[R] Help with PCA
William Revelle
lists at revelle.net
Fri Dec 30 16:43:00 CET 2011
Sarah and elisacarli21
principal in the psych package will do principal components of a correlation or covariance matrix.
ex:
library(psych)
principal(Thurstone,3,rotate="none") #First three principal components of the Thurstone correlation matrix
#compare with eigen
e <- eigen(Thurstone) #perform an eigen value decomposition
e #show the resuls
e$vectors %*% diag(sqrt(e$values)) #convert to "loadings" and compare with the output from principal
Bill
On Dec 28, 2011, at 9:09 AM, Sarah Goslee wrote:
> Hi,
>
> On Wed, Dec 28, 2011 at 7:54 AM, elisacarli21 <elisacarli21 at gmail.com> wrote:
>> Dear all,
>>
>> I've a correlation matrix with rows and columns headings.
>> I've two questions:
>>
>> 1) How can i import it in R, setting first row as row heading and first
>> column as column heading?
>
> read.table, with the appropriate options. You can see what they are
> by typing
> ?read.table
> at an R prompt.
>
>> 2) Which is the best principal component anlysis package in R?
>
> Best for what?
>
> I'd start with
> ?princomp
> and if that doesn't meet your needs go looking farther.
> www.rseek.org is good for finding R functions for particular purposes.
>
> But if you're starting with the correlation matrix rather than the raw
> data, you might need to do the eigenanalysis yourself rather than
> relying on an existing function that assumes raw data.
>
> Sarah
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
William Revelle http://personality-project.org/revelle.html
Professor http://personality-project.org
Department of Psychology http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 6 minutes to midnight http://www.thebulletin.org
More information about the R-help
mailing list