View source: R/bm_SampleFactorLevels.R
bm_SampleFactorLevels | R Documentation |
This internal biomod2 function allows the user to sample all levels of all
the factorial variables contained in a data.frame
or SpatRaster
object.
bm_SampleFactorLevels(expl.var, mask.out = NULL, mask.in = NULL)
expl.var |
a |
mask.out |
a |
mask.in |
a |
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
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.
Damien Georges
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()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.