pca: Principle Component Analysis

pcaR Documentation

Principle Component Analysis

Description

pca performs a principal components analysis (using princomp function from stats package) on the given numeric data matrix and returns the results as an object of class princomp.

Usage

## S4 method for signature 'sdmdata'
pca(x,scale,filename,...)

## S4 method for signature 'data.frame'
pca(x,scale,filename,...)

## S4 method for signature 'RasterStackBrick'
pca(x,scale,filename,...)

## S4 method for signature 'SpatRaster'
pca(x,scale,filename,...)

Arguments

x

sdmdata object, or a data.frame, or a Raster (either RasterStackBrick or SpatRaster) object

scale

logical; specifies whether the input data should be scaled (by subtracting the variable's mean, then dividing it by its standard deviation)

filename

optional character; specifies a filename that should be either a CSV file when x is sdmdata or data.frame, or a Raster file when x is a Raster object

...

additional arguments pass to princomp function

Details

pca analysis can be considered as a way to deal with multicollinearity problem and/or reduction of the data dimention. It returns two items in a list including data, and pca. The data contains the transoformed data into priciple components (the number of components is the same as the number of variables in the input data). You can check the pca item to see how many components (e.g., first 3) should be selected (e.g., by checking loadings). For more information on the calculation, see the princomp function.

Value

a list including data (a data.frame or a RasterStack depending on the type of x), and pca results (output of the princomp function)

Author(s)

Babak Naimi naimi.b@gmail.com

https://r-gis.net/

https://www.biogeoinformatics.org/

Examples

filename <- system.file('external/predictors.tif',package='sdm')

r <- rast(filename)

p <- pca(r) # p is a .pcaObject

p

plot(p@pcaObject) # or biplot(p@pcaObject)

plot(p@data)

babaknaimi/sdm documentation built on April 4, 2024, 1:45 p.m.