R: Principal Component Analysis

principal_components {anomalyDetection} | R Documentation

## Principal Component Analysis

### Description

`principal_components` relates the data to a set of a components through the eigen-decomposition of the correlation matrix, where each component explains some variance of the data and returns the results as an object of class prcomp.

### Usage

    principal_components(data, retx = TRUE, center = TRUE, scale. = FALSE,
      tol = NULL, ...)

### Arguments

`data` | numeric data.
`retx` | a logical value indicating whether the rotated variables should be returned.
`center` | a logical value indicating whether the variables should be shifted to be zero centered. Alternately, a vector of length equal the number of columns of x can be supplied. The value is passed to scale.
`scale.` | a logical value indicating whether the variables should be scaled to have unit variance before the analysis takes place. The default is FALSE for consistency with S, but in general scaling is advisable. Alternatively, a vector of length equal the number of columns of `data` can be supplied. The value is passed to scale.
`tol` | a value indicating the magnitude below which components should be omitted. (Components are omitted if their standard deviations are less than or equal to tol times the standard deviation of the first component.) With the default null setting, no components are omitted. Other settings for tol could be `tol = 0` or `tol = sqrt(.Machine$double.eps)`, which would omit essentially constant components.
`...` | arguments passed to or from other methods.

### Details

The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy

### Value

`principal_components` returns a list containing the following components:

1. `pca_sdev`: the standard deviations of the principal components (i.e., the square roots of the eigenvalues of the correlation matrix, though the calculation is actually done with the singular values of the data matrix).

2. `pca_loadings`: the matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors).

3. `pca_rotated`: if `retx` is `TRUE` the value of the rotated data (the centred (and scaled if requested) data multiplied by the rotation matrix) is returned. Hence, `cov(x)` is the diagonal matrix `diag(sdev^2)`.

4. `pca_center`: the centering used

5. `pca_scale`: whether scaling was used

### See Also

`prcomp`, `biplot.prcomp`, `screeplot`, `cor`, `cov`, `svd`, `eigen`

### Examples

    x <- matrix(rnorm(200 * 3), ncol = 10)
    principal_components(x)
    principal_components(x, scale = TRUE)

[Package anomalyDetection version 0.2.5 Index]