Subsets an attribute-based presence-absence matrix (PAM) generated by
lets.attrpam by retaining only a selected set of species.
Species not included in names are removed from the PAM, while the
first three columns of the PAM table are always preserved because they store
attribute-space cell metadata. After subsetting, species richness is
recalculated for each attribute-space cell and written back to the associated
raster object.
Arguments
- x
A PAM in attribute space produced by
lets.attrpam. This object is expected to be a list in which:x[[1]]is a data frame containing attribute-space cells in rows, the first three columns as cell metadata, and species occurrences in the remaining columns.x[[2]]is aterra::SpatRasterrepresenting the attribute-space grid.
- species
A character vector with species names to retain in the PAM.
- remove.cells
Logical. If
TRUE, attribute-space cells with zero richness after subsetting are removed from the data-frame component (x[[1]]). Default isTRUE.
Value
A list with the same structure as the input object:
x[[1]]: the subsetted attribute PAM table.x[[2]]: the attribute-space raster with richness values updated according to the retained species.
Details
Optionally, attribute-space cells with zero richness after subsetting can be removed from the tabular component of the PAM.
The function assumes that the first three columns of x[[1]] contain
non-species information and therefore always preserves them during
subsetting. Richness is recalculated as the row sum across all retained
species columns.
If none of the supplied species names match the species present in the PAM, the function stops with an error.
Examples
if (FALSE) { # \dontrun{
n <- 2000
Species <- paste0("sp", 1:n)
trait_a <- rnorm(n)
trait_b <- trait_a * 0.2 + rnorm(n)
x <- data.frame(Species, trait_a, trait_b)
pam_att <- lets.attrpam(x, n_bins = 30)
names <- sample(Species, 200)
pam_sub <- lets.subsetPAMatt(pam_att, names)
lets.plot.attrpam(pam_sub)
} # }