pca_raster: Principal component analysis for raster layers

View source: R/pca_raster.R

pca_rasterR Documentation

Principal component analysis for raster layers

Description

pca_raster performs a principal component analysis with a set of variables and returns results including PCs as raster layers. If needed, principal components can be projected to other scenarios.

Usage

pca_raster(variables, in_format = NULL, scale = TRUE, center = TRUE,
           n_pcs = NULL, project = FALSE, projection_variables,
           return_projection = FALSE, write_to_directory = FALSE,
           out_format = "GTiff", output_directory, overwrite = FALSE)

Arguments

variables

SpatRaster or character. If SpatRaster, stack of layers to be used; if character, name of the folder where environmental variables are.

in_format

(character) if class of variables = "character", format of variables in such a folder. Options are "ascii", "GTiff", and "EHdr" = bil. Default = NULL.

scale

(logical) whether or not to scale variables while performing principal component analyses.

center

(logical) whether or not to center variables while performing principal component analyses.

n_pcs

(numeric) number of principal components to be returned as raster layers. By default all principal components are returned.

project

(logical) whether or not to project the species niche to other scenario(s). If TRUE, argument projection_variables must be defined. Default = FALSE.

projection_variables

character or SpatRaster. If character, name of the folder where one or more sub-directories containing variables of distinct environmental scenarios are (useful if multiple projections are needed). If SpatRaster, stack of variables representing one scenario for projection. Variable names must correspond with those of variables (i.e., their names must match).

return_projection

(logical) whether to return raster PCs for projection scenario(s) as part of the resulting list. Default = FALSE.

write_to_directory

(logical) whether to write results in output_directory. Default = FALSE.

out_format

(character) format of layers to be written in output_directory. Options are "ascii", "GTiff", and "EHdr" = bil. Default = "GTiff".

output_directory

(character) name of the folder to be created to save results.

overwrite

(logical) whether or not to overwrite the output_directory if it already exists. Default = FALSE.

Value

A list containing:

  • PCA results

  • SpatRaster of principal components for variables

  • if return_projection = TRUE, list of SpatRaster objects with principal components for other scenarios. NULL if project = FALSE.


fmachados/grinnell documentation built on Jan. 29, 2024, 6:48 p.m.