prepare_master_matrix {biosurvey}R Documentation

Prepare a base object to perform further analyses


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.


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



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


RasterStack or RasterBrick of environmental variables.


(optional) SpatialPolygons* 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.


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.


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


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


(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.


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


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


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.


An S3 object of class master_matrix containing the following elements:


# Data
data("mx", package = "biosurvey")
variables <- raster::stack(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)

[Package biosurvey version 0.1.1 Index]