This internal biomod2 function allows to convert probability (not necessary between 0 and 1) values into binary presence-absence (0 or 1) values according to a predefined threshold (see Details).

bm_BinaryTransformation(data, threshold, do.filtering = FALSE)

# S4 method for class 'data.frame'
bm_BinaryTransformation(data, threshold, do.filtering = FALSE)

# S4 method for class 'matrix'
bm_BinaryTransformation(data, threshold, do.filtering = FALSE)

# S4 method for class 'numeric'
bm_BinaryTransformation(data, threshold, do.filtering = FALSE)

# S4 method for class 'SpatRaster'
bm_BinaryTransformation(data, threshold, do.filtering = FALSE)

Arguments

data

a vector, a matrix, data.frame, or a SpatRaster containing the data to be converted

threshold

a numeric or a vector of numeric corresponding to the threshold used to convert the given data

do.filtering

(optional, default FALSE)
A logical value defining whether filtered data should be returned, or binary one (see Details)

Value

An object of the same class than data and containing either binary (0 or 1) values, or filtered values.

Details

If data is a vector, threshold should be a single numeric value.
If data is a matrix, data.frame or SpatRaster, threshold should be a vector containing as many values as the number of columns or layers contained in data. If only one numeric value is given, the same threshold will be applied to all columns or layers.

If do.filtering = FALSE, binary (0 or 1) values are returned.
If do.filtering = TRUE, values will be filtered according to threshold, meaning that :

  • data < threshold will return 0

  • data >= threshold will return the actual values of data (not transformed in 1)

Author

Wilfried Thuiller, Damien Georges

Examples


## Generate a 0-1000 vector (normal distribution)
vec.d <- rnorm(100, 500, 100)

## From continuous to binary / filtered vector
vec.d_bin <- bm_BinaryTransformation(data = vec.d, threshold = 500)
vec.d_filt <- bm_BinaryTransformation(data = vec.d, threshold = 500, do.filtering = TRUE)
cbind(vec.d, vec.d_bin, vec.d_filt)