bm_SampleFactorLevels {biomod2}R Documentation

Tool to ensure the sampling of all levels of a factorial variable

Description

This internal biomod2 function samples randomly an element of each level of all the factorial variables contained in a raster* or data.frame 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 :

If mask.in contains several masks (either it is a RasterStack object or a multi-columns data.frame), then the order of masks / columns matters : they will be considered successively to sample missing factor levels.

Value

A numeric vector containing point IDs (either cell number for raster* objects, or row number for data.frame), each refering to a single level of a single factorial variable.

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

Author(s)

Damien Georges

See Also

bm_PseudoAbsences, bm_RunModelsLoop, BIOMOD_Modeling

Other Secundary functions: bm_BinaryTransformation(), bm_CVnnet(), bm_CrossValidation(), bm_FindOptimStat(), bm_MakeFormula(), bm_PlotEvalBoxplot(), bm_PlotEvalMean(), bm_PlotRangeSize(), bm_PlotResponseCurves(), bm_PlotVarImpBoxplot(), bm_PseudoAbsences(), bm_RunModelsLoop(), bm_SRE(), bm_SampleBinaryVector(), 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)



[Package biomod2 version 4.2-4 Index]