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 sdmdata
pca(x,scale,filename,...)
# S4 method for data.frame
pca(x,scale,filename,...)
# S4 method for RasterStackBrick
pca(x,scale,filename,...)
# S4 method for SpatRaster
pca(x,scale,filename,...)
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)
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
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.
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)