# pca: Principal Components Analysis In labdsv: Ordination and Multivariate Analysis for Ecology

## Description

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

## Usage

 ```1 2 3 4 5 6 7 8``` ```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) varplot.pca(x, dim=length(x\$sdev)) ```

## Arguments

 `mat` a matrix or data.frame 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 ‘dsvord’ and type='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

## 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.

## Value

an object of class "pca", a list with components:

 `scores` a matrix of the coordinates of the samples in the reduced space `loadings` a matrix of the contributions of the variables to the axes of the reduced space. `sdev` a vector of standard deviations for each dimension

## Note

The current version of pca is based on the `prcomp` function, as opposed to the `princomp` function. Nonetheless, it maintains the more conventional labels "scores" and "loadings", rather than x and rotation. prcomp is based on a singular value decomposition algorithm, as has worked better in my experience. In the rare cases where it fails, you may want to try `princomp`.

## References

http://ecology.msu.montana.edu/labdsv/R/labs/lab7/lab7.html

`princomp`, `prcomp`, `pco`, `nmds`, `fso`, `cca`

## Examples

 ```1 2 3 4 5 6 7``` ```data(bryceveg) # returns a vegetation data.frame 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') ```

### Example output ```Loading required package: mgcv
This is mgcv 1.8-28. For overview type 'help("mgcv-package")'.

Attaching package: 'labdsv'

The following object is masked from 'package:stats':

density

Family: gaussian

Formula:
var ~ s(x, y)

Estimated degrees of freedom:
20  total = 21.03

GCV score: 197223.4
D^2 =  0.6057
```

labdsv documentation built on Aug. 4, 2019, 5:03 p.m.