Hello again, I was hoping one of you could help me with this problem. Consider the sample data from R:> summary(prcomp(USArrests))Importance of components: PC1 PC2 PC3 PC4 Standard deviation 83.732 14.2124 6.4894 2.48279 Proportion of Variance 0.966 0.0278 0.0058 0.00085 Cumulative Proportion 0.966 0.9933 0.9991 1.00000 How do I access the information contained within this summary? For instance, let's say I wanted to make a graph based on the second row ("Proportion of Variance"). Please rest assured this is not a homework assignment. I'm just a relatively novice R user trying to do stuff that's often over my head. Thanks in advance, ----------------------------------- Josh Banta, Ph.D Center for Genomics and Systems Biology New York University 100 Washington Square East New York, NY 10003 Tel: (212) 998-8465 http://plantevolutionaryecology.org [[alternative HTML version deleted]]
Erik Iverson
2010-Jun-16 19:35 UTC
[R] Accessing the elements of summary(prcomp(USArrests))
Josh B wrote:> Hello again, > > I was hoping one of you could help me with this problem. Consider the > sample data from R: > >> summary(prcomp(USArrests)) > Importance of components: PC1 PC2 PC3 PC4 Standard > deviation 83.732 14.2124 6.4894 2.48279 Proportion of Variance > 0.966 0.0278 0.0058 0.00085 Cumulative Proportion 0.966 0.9933 > 0.9991 1.00000 > > How do I access the information contained within this summary? For > instance, let's say I wanted to make a graph based on the second row > ("Proportion of Variance"). >The easiest way is to use the ?str function to see how an object is put together. So, assign the results of the summary to a variable x <- summary(prcomp(USArrests)) then str(x) will lead you to : plot(x$importance[2, ], type = "l")
Prof Brian Ripley
2010-Jun-16 21:15 UTC
[R] Accessing the elements of summary(prcomp(USArrests))
Hints: (i) List the function by stats:::summary.prcomp . You will see that the table is component 'importance' of the list result. So take a look at summary(prcomp(USArrests))$importance[2, ] (ii) This looks a lot like screeplot(). (iii) prcomp(USArrests) is inappropriate, as the help file for prcomp stresses. On Wed, 16 Jun 2010, Josh B wrote:> Hello again, > > I was hoping one of you could help me with this problem. Consider the sample data from R: > >> summary(prcomp(USArrests)) > Importance of components: > PC1 PC2 PC3 PC4 > Standard deviation 83.732 14.2124 6.4894 2.48279 > Proportion of Variance 0.966 0.0278 0.0058 0.00085 > Cumulative Proportion 0.966 0.9933 0.9991 1.00000 > > How do I access the information contained within this summary? For instance, let's say I wanted to make a graph based on the second row ("Proportion of Variance"). > > Please rest assured this is not a homework assignment. I'm just a relatively novice R user trying to do stuff that's often over my head. > > Thanks in advance, > ----------------------------------- > Josh Banta, Ph.D > Center for Genomics and Systems Biology > New York University > 100 Washington Square East > New York, NY 10003 > Tel: (212) 998-8465 > http://plantevolutionaryecology.org > > > > [[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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595