Skip to contents

prepare an S3 object that will serve as the base to perform all further analyses. This object will contain geographic and environmental information that will be used to characterize the region of interest.

Usage

prepare_master_matrix(region, variables, mask = NULL,
                      preselected_sites = NULL, do_pca = FALSE,
                      center = TRUE, scale = FALSE,
                      variables_in_matrix = NULL, verbose = TRUE)

Arguments

region

SpatVector of the region of interest; for instance, a country, another type of administrative are, or a protected area.

variables

SpatRaster of environmental variables.

mask

(optional) SpatVector object to mask variables and reduce region to an area that is more relevant for analysis (e.g., only areas with natural vegetation cover). Default = NULL.

preselected_sites

data.frame containing sites that must be included in posterior selections of sites for the survey system. Columns must be: "Sites", "Longitude", "Latitude", in that order.

do_pca

(logical) whether or not to perform a principal component analysis. Default = FALSE.

center

(logical) whether or not to center variables. Argument to be passed to the function prcomp. Default = TRUE.

scale

(logical) whether or not to scale the variables. Recommended when variables are in different units. Argument to be passed to the function prcomp. Default = FALSE.

variables_in_matrix

(character) name of variables to include in matrix. If NULL (the default) all variables will be included.

verbose

(logical) whether or not to print messages about the process. Default = TRUE.

Value

An S3 object of class master_matrix containing the following elements:

  • data_matrix: a date.frame with information about geographic location of raster cells, initial environmental data, and if do_pca is TRUE, the first two principal components derived from original data.

  • region: a SpatVector representing the region of interest.

  • mask: SpatVector object used. NULL if mask was not defined.

  • preselected_sites: sites defined by used. NULL if preselected_sites was not defined.

  • raster_base: a SpatRaster representing the raster masked to region or mask, which will be used for plotting purposes.

  • PCA_results: if do_pca is TRUE, other results from principal component analysis. If FALSE, PCA_results element of the object is NULL.

Details

This function helps in preparing all data as needed for further analyses aiming to define a survey sampling system considering geographic and environmental spaces in the region of interest.

If mask is defined all analyses will be restricted to such an area. If mask is not fully contained by region, the mask used for reducing variables, and returned as part of the S3 object (master_matrix) is the intersection between them.

If preselected_sites is defined, environmental values and, if do_pca = TRUE, principal components are added to such records. These records and their characteristics will be considered in further analyses.

Examples

# Data
mx <- terra::vect(system.file("extdata/mx.gpkg", package = "biosurvey"))

variables <- terra::rast(system.file("extdata/variables.tif",
                                       package = "biosurvey"))

# Create master matrix object
m_matrix <- prepare_master_matrix(region = mx, variables = variables,
                                  do_pca = TRUE, center = TRUE, scale = TRUE)
#> Processing raster layers, please wait...
#> Performing PCA analysis