| bm_SampleFactorLevels {biomod2} | R 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 |
mask.out |
a |
mask.in |
a |
Details
The expl.var, mask.out and mask.in parameters must be coherent in terms of
dimensions :
same number of rows for
data.frameobjectssame resolution, projection system and number of cells for
SpatRasterobjects
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.framewill be understood as :-
FALSE: out of mask -
TRUE: in mask
-
Values in
SpatRasterwill 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)