bm_SampleFactorLevels: Sample all levels of a factorial variable

View source: R/bm_SampleFactorLevels.R

bm_SampleFactorLevelsR Documentation

Sample all levels of a factorial variable

Description

This internal biomod2 function allows the user to sample all levels of all the factorial variables contained in a data.frame or SpatRaster object.

Usage

bm_SampleFactorLevels(expl.var, mask.out = NULL, mask.in = NULL)

Arguments

expl.var

a data.frame or SpatRaster object containing the explanatory variables (in columns or layers)

mask.out

a data.frame or SpatRaster object containing the area that has already been sampled (factor levels within this mask will not be sampled)

mask.in

a data.frame or SpatRaster object containing areas where factor levels are to be sampled in priority. Note that if after having explored these masks, some factor levels remain unsampled, they will be sampled in the reference input object expl.var.

Details

The expl.var, mask.out and mask.in parameters must be coherent in terms of dimensions :

  • same number of rows for data.frame objects

  • same resolution, projection system and number of cells for SpatRaster objects

If mask.in contains several columns (data.frame) or layers (SpatRaster), then their order matters : they will be considered successively to sample missing factor levels.

  • Values in data.frame will be understood as :

    • FALSE : out of mask

    • TRUE : in mask

  • Values in SpatRaster will be understood as :

    • NA : out of mask

    • not NA : in mask

Value

A vector of numeric values corresponding to either row (data.frame) or cell (SpatRaster) numbers, each refering to a single level of a single factorial variable.

In case no factorial variable is found in the input object, NULL is returned.

Author(s)

Damien Georges

See Also

bm_PseudoAbsences, bm_CrossValidation

Other Secundary functions: bm_BinaryTransformation(), bm_CrossValidation(), bm_FindOptimStat(), bm_MakeFormula(), bm_ModelingOptions(), bm_PlotEvalBoxplot(), bm_PlotEvalMean(), bm_PlotRangeSize(), bm_PlotResponseCurves(), bm_PlotVarImpBoxplot(), bm_PseudoAbsences(), bm_RunModelsLoop(), bm_SRE(), bm_SampleBinaryVector(), bm_Tuning(), bm_VariablesImportance()

Examples

library(terra)

## Create raster data
ras.1 <- ras.2 <- mask.out <- rast(nrows = 10, ncols = 10)
ras.1[] <- as.factor(rep(c(1, 2, 3, 4, 5), each = 20))
ras.1 <- as.factor(ras.1)
ras.2[] <- rnorm(100)
stk <- c(ras.1, ras.2)
names(stk) <- c("varFact", "varNorm")

## define a mask for already sampled points
mask.out[1:40] <- 1

## define a list of masks where we want to sample in priority
mask.in <- list(ras.1, ras.1)
mask.in[[1]][1:80] <- NA ## only level 5 should be sampled in this mask
mask.in[[1]][21:80] <- NA ## only levels 1 and 5 should be sampled in this mask

## Sample all factor levels
samp1 <- bm_SampleFactorLevels(expl.var = stk, mask.out = mask.out)
samp2 <- bm_SampleFactorLevels(expl.var = stk, mask.in = mask.in)
samp3 <- bm_SampleFactorLevels(expl.var = stk, mask.out = mask.out, mask.in = mask.in)



biomodhub/biomod2 documentation built on April 30, 2024, 2:32 a.m.