Learn R Programming

labdsv (version 1.2-0)

pca: Principal Components Analysis

Description

Principal components analysis is a eigenanalysis of a correlation or covariance matrix used to project a high-dimensional system to fewer dimensions.

Usage

pca(mat, cor = FALSE, dim = min(nrow(mat),ncol(mat)))
## S3 method for class 'pca':
summary(object, dim = length(object$sdev), ...)
## S3 method for class 'pca':
scores(x, labels = NULL, dim = length(x$sdev))
## S3 method for class 'pca':
loadings(x, dim = length(x$sdev), digits = 3, cutoff = 0.1)

Arguments

mat
a matrix or dataframe of interest, samples as rows, attributes as columns
cor
logical: whether to use a correlation matrix (if TRUE), or covariance matrix (if FALSE)
dim
the number of dimensions to return
object
an object of class pca
x
an object of class pca
labels
an (optional) vector of labels to identify points
digits
number of digits to report
cutoff
threshold to suppress printing small values
...
arguments to pass to function summary

Value

  • an object of class "pca", a list with components:
  • scoresa matrix of the coordinates of the samples in the reduced space
  • loadingsa matrix of the contributions of the variables to the axes of the reduced space.
  • sdeva vector of standard deviations for each dimension

Details

PCA is a common multivariate technique. The version here is simply a wrapper for the prcomp function to make its use and plotting consistent with the other LabDSV functions

References

http://ecology.msu.montana.edu/labdsv/R

See Also

princomp, prcomp, pco, nmds, fso, cca

Examples

Run this code
data(bryceveg) # returns a vegetation dataframe
    data(brycesite)
    x <- pca(bryceveg,dim=10)  # returns the first 10 eigenvectors and loadings
    plot(x)
    surf(x,brycesite$elev)
    points(x,brycesite$depth=='deep')

Run the code above in your browser using DataLab