Home > other >  Summary function for principal coordinates analysis
Summary function for principal coordinates analysis

Time:11-22

R function prcomp() for performing principal components analysis provides a handy summary() method which (as is expected) offers a summary of the results at a glance:

data(cars)
pca <- prcomp(cars)
summary(pca)

Importance of components:
                           PC1     PC2
Standard deviation     26.1252 3.08084
Proportion of Variance  0.9863 0.01372
Cumulative Proportion   0.9863 1.00000

I would like a similar summary for displaying the results of a principal coordinates analysis, usually performed using the cmdscale() function:

pco <- cmdscale(dist(cars), eig=TRUE)

But this function does not provide a summary() method and therefore there is no direct way of displaying the results as percent variances, etc.

Has anyone out there already developed some simple method for summarizing such results from PCO?

Thanks in advance for any assistance you can provide!

With best regards,

CodePudding user response:

Instead of the basic cmdscale, one can use capscale or dbRda from package vegan instead. These functions generalize PCO as they "also perform unconstrained principal coordinates analysis, optionally using extended dissimilarities" (citation from ?capscale help page). This is much more than a workaround.

The following gives an example:

library(vegan)

A <- data.frame(
  x = c(-2.48, -4.03, 1.15, 0.94, 5.33, 4.72),
  y = c(-3.92, -3.4, 0.92, 0.78, 3.44, 0.5),
  z = c(-1.11, -2.18, 0.21, 0.34, 1.74, 1.12)
)

pco <- capscale(dist(A) ~ 1) # uses euclidean distance
# or
pco <- capscale(A ~ 1)  # with same result


pco # shows some main results
summary(pco) # shows more  results, including eigenvalues

The summary function has several arguments, documented in ?summary.cca. Parts of the result can be extracted and formated by the user, the eigenvalues for example with pco$CA$eig.

  •  Tags:  
  • r
  • Related