# Standardize a value between -1 and 1 to its corresponding value in the 0-to-1 scale (or vice-versa)

While most of the threshold-based measures of model evaluation range theoretically from 0 to 1, some of them (such as Cohen’s kappa and the true skill statistic TSS) may range from -1 to 1 (Allouche et al. 2006). Thus, the values of different measures may not be directly comparable. We don’t usually get negative values of TSS or kappa (nor values under 0.5 for CCR or AUC, for example) because that only happens when model predictions perform worse than random guesses; still, such values are mathematically possible, and can occur e.g. when extrapolating models to regions where where the species-environment relationships differ.

The standard01 function, now included in the modEvA package (Barbosa et al. 2014), converts the score of a measure that ranges from -1 to 1 (e.g. a kappa or TSS value obtained for a model) into its corresponding value in 0-to-1 scale, so that it can be compared directly with measures that range between 0 and 1 (such as CCR or AUC). This standardization is now included as an option in the threshMeasures function, which had been producing slightly unfair barplots of measure comparison. The default direction of the standardizaion is “-1+1to01”, but the function can also perform the conversion backwards by setting direction = “01to-1+1”.

```standard01 <-
function(score, direction = c("-1+1to01", "01to-1+1")) {
# version 1.1 (11 June 2014)
# standardizes a value between -1 and 1 to its corresponding value in the 0-1 scale, or vice-versa

direction <- match.arg(direction, c("-1+1to01", "01to-1+1"))

if (direction == "-1+1to01") {
if (score < -1 | score > 1) stop("'score' must be between -1 and 1")
std.score <- score + ((1 - score) / 2)
}  # end if -1+1to01
else {
if (score < 0 | score > 1) stop("'score' must be between 0 and 1 to standardize in this direction")
std.score <- 2 * (score - 0.5)
}
return(std.score)
}```

[presented with Pretty R]

To try it, just give it a value between -1 and 1 (or between 0 and 1 if converting in the opposite direction) to get the result:

standard01(0.6)

standard01(0.6, direction = “-1+1to01”)

standard01(0.6, direction = “01to-1+1”)

Note that this is not the same as re-scaling and stretching a vector of values so that they range between 0 and 1 (i.e., the lowest value becomes 0, the highest becomes 1, and the ones in the midlle retain their rank and relative diference). This can be achieved with the range01 function, which I got from here and adapted to handle also missing values. This function is also included in modEvA.

```range01 <- function(x, na.rm = TRUE) {
# version 1.1 (9 Aug 2013)
(x - min(x, na.rm = na.rm)) / (max(x, na.rm = na.rm) - min(x, na.rm = na.rm))
}```

range01(0:10)

range01(-12.3 : 21.7)

References:

Barbosa A.M., Brown J.A. & Real R. (2014) modEvA – an R package for model evaluation and analysis. R package, version 0.1.

Allouche, O., Tsoar, A. & Kadmon, R. (2006) Assessing the accuracy of species distribution models: prevalence, kappa and the true skill statistic (TSS). Journal of Applied Ecology, 43, 1223–1232.