[R] PCA - scores
William Revelle
lists at revelle.net
Fri Mar 4 05:42:18 CET 2011
Shari,
Josh partly answered your question, but his example did not include
rotation because he took out just one factor.
Try:
require(psych)
mt.pc <- principal(mtcars,3,scores=TRUE) #this gives you the
varimax rotated first 3 principal components
#pc.scores <- mt.pc$scores #here are the scores
biplot(mt.pc) #show the data as well as the principal components in a biplot
Bill
At 5:15 PM -0800 3/3/11, Joshua Wiley wrote:
>Hi Shari,
>
>Yes, please look at the documentation for principal. You can access
>this (assuming you have loaded psych) by typing at the console:
>
>?principal
>
>note the logical argument "scores".
>
>Here is a small example:
>
>##############################
>require(psych)
>require(GPArotation)
>
>dat <- principal(mtcars[, c("mpg", "hp", "wt")], nfactors = 1,
> rotate = "oblimin", scores = TRUE)
>
>dat$scores
>##############################
>
>Cheerio,
>
>Josh
>
>On Thu, Mar 3, 2011 at 1:02 PM, Shari Clare <sclare at ualberta.ca> wrote:
>> I am running a PCA, but would like to rotate my data and limit the
>> number of factors that are analyzed. I can do this using the
>> "principal" command from the psych package [principal(my.data,
>> nfactors=3,rotate="varimax")], but the issue is that this does not
>> report scores for the Principal Components the way "princomp" does.
>>
>> My question is:
>>
>> Can you get an output of scores using "principal" OR, is there a way
>> to limit the number of factors that are included when you use
>> "princomp"?
>>
>> Thanks,
>> Shari Clare
>>
>> PhD Candidate
>> Department of Renewable Resources
>> University of Alberta
>> sclare at ualberta.ca
>> 780-492-2540
>>
>>
>>
>>
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
>
>
>--
>Joshua Wiley
>Ph.D. Student, Health Psychology
>University of California, Los Angeles
>http://www.joshuawiley.com/
>
>______________________________________________
>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.
More information about the R-help
mailing list