This function allows to add predictors to distribution or BiodiversityScenario objects. Predictors are covariates that in spatial projection have to match the geographic projection of the background layer in the distribution object. This function furthermore allows to transform or create derivates of provided predictors.

A transformation takes the provided rasters and for instance rescales them or
transforms them through a principal component analysis (prcomp). In
contrast, derivates leave the original provided predictors alone, but instead
create new ones, for instance by transforming their values through a
quadratic or hinge transformation. Note that this effectively increases the
number of predictors in the object, generally requiring stronger
regularization by the used `Engine`

. Both transformations and derivates can
also be combined. Available options for transformation are:

`'none'`

- Leaves the provided predictors in the original scale.`'pca'`

- Converts the predictors to principal components. Note that this results in a renaming of the variables to principal component axes!`'scale'`

- Transforms all predictors by applying scale on them.`'norm'`

- Normalizes all predictors by transforming them to a scale from 0 to 1.`'windsor'`

- Applies a windsorization to the target predictors. By default this effectively cuts the predictors to the 0.05 and 0.95, thus helping to remove extreme outliers.

Available options for creating derivates are:

`'none'`

- No additional predictor derivates are created.`'quad'`

- Adds quadratic transformed predictors.`'interaction'`

- Add interacting predictors. Interactions need to be specified (`"int_variables"`

)!`'thresh'`

- Add threshold transformed predictors.`'hinge'`

- Add hinge transformed predictors.`'bin'`

- Add predictors binned by their percentiles.

## Usage

```
add_predictors(
x,
env,
names = NULL,
transform = "scale",
derivates = "none",
derivate_knots = 4,
int_variables = NULL,
bgmask = TRUE,
harmonize_na = FALSE,
explode_factors = FALSE,
priors = NULL,
...
)
# S4 method for BiodiversityDistribution,SpatRasterCollection,ANY,character,character,numeric,ANY,logical,logical,logical,ANY
add_predictors(x,env,names,transform,derivates,derivate_knots,int_variables,bgmask,harmonize_na,explode_factors,priors,...)
# S4 method for BiodiversityDistribution,SpatRaster,ANY,character,character,numeric,ANY,logical,logical,logical,ANY
add_predictors(x,env,names,transform,derivates,derivate_knots,int_variables,bgmask,harmonize_na,explode_factors,priors,...)
# S4 method for BiodiversityDistribution,stars,ANY,character,character,numeric,ANY,logical,logical,logical,ANY
add_predictors(x,env,names,transform,derivates,derivate_knots,int_variables,bgmask,harmonize_na,explode_factors,priors,...)
# S4 method for BiodiversityScenario,SpatRaster,ANY,character,character,numeric,ANY,logical
add_predictors(x,env,names,transform,derivates,derivate_knots,int_variables,harmonize_na,...)
# S4 method for BiodiversityScenario,stars,ANY,character,character,numeric,ANY,logical
add_predictors(x,env,names,transform,derivates,derivate_knots,int_variables,harmonize_na,...)
```

## Arguments

- x
`distribution()`

(i.e.`BiodiversityDistribution`

) object.- env
A

`SpatRaster`

or`stars`

object.- names
A

`vector`

of character names describing the environmental stack in case they should be renamed.- transform
A

`vector`

stating whether predictors should be preprocessed in any way (Options:`'none'`

,`'pca'`

,`'scale'`

,`'norm'`

)- derivates
A Boolean check whether derivate features should be considered (Options:

`'none'`

,`'thresh'`

,`'hinge'`

,`'quad'`

) )- derivate_knots
A single

`numeric`

or`vector`

giving the number of knots for derivate creation if relevant (Default:`4`

).- int_variables
A

`vector`

with length greater or equal than`2`

specifying the covariates (Default:`NULL`

).- bgmask
Check whether the environmental data should be masked with the background layer (Default:

`TRUE`

).- harmonize_na
A

`logical`

value indicating of whether NA values should be harmonized among predictors (Default:`FALSE`

).- explode_factors
`logical`

of whether any factor variables should be split up into binary variables (one per class). (Default:`FALSE`

).- priors
A

`PriorList`

object. Default is set to`NULL`

which uses default prior assumptions.- ...
Other parameters passed down

## Note

**Important:**
Not every `Engine`

supported by the ibis.iSDM R-package allows
missing data points among extracted covariates. Thus any observation with
missing data is generally removed prior from model fitting. Thus ensure that
covariates have appropriate no-data settings (for instance setting `NA`

values to `0`

or another out of range constant).

Not every engine does actually need covariates. For instance it is perfectly legit to fit a model with only occurrence data and a spatial latent effect (add_latent_spatial). This correspondents to a spatial kernel density estimate.

Certain names such `"offset"`

are forbidden as predictor variable names.
The function will return an error message if these are used.

## Examples

```
if (FALSE) {
obj <- distribution(background) |>
add_predictors(covariates, transform = 'scale')
obj
}
```