biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
87 stars 22 forks source link

Question about generating AUC graph - How could I create it? #498

Closed gsatta closed 2 days ago

gsatta commented 2 months ago

Dear all, Is it possible to generate a graph of AUC like, for example, the one below using biomod2 or other packages?

How could I create it?

Thank you.

image

HeleneBlt commented 2 months ago

Hello Gabriele,

Sorry, biomod2 doesn't generate the ROC curve.

You can have a look at the packages : pROC, plotROC or ROCit.

Hope it helps ! Hélène

EdSacre commented 1 month ago

Hi Gabriele,

I was wanting to do a similar thing, so I wrote a function for it. Hope you find it useful.

# mod = BIOMOD.models.out object
# mod_methods = vector of algos, e.g. c("GBM", "XGBOOST")

require(pROC)

bm_ROC <- function(mod, mod_methods){

  obs <- get_formal_data(mod)@data.species
  train <- get_calib_lines(mod)
  if(any(colnames(train) == "_allData_allRun")){
    train <- train[ , -which(colnames(train) %in% c("_allData_allRun"))]
  }
  cv_runs <- ncol(train)

  par(mfrow = c(length(mod_methods), cv_runs), mar = c(12, 5, 5, 5))

  for(i in 1:length(mod_methods)){
    for(j in 1:ncol(train)){
      predictions <- get_predictions(mod, model.as.col = T, algo = mod_methods[i])
      predictions <- predictions / 1000
      p_train <- predictions[train[,j],j]
      p_test <- predictions[!train[,j],j]
      r_train <- obs[train[,j]]
      r_test <- obs[!train[,j]]

      n <- paste0(mod_methods[i], "_RUN", j)
      pROC::plot.roc(r_train, p_train, col = "blue", main = n, quiet = T)
      pROC::plot.roc(r_test, p_test, col = "red", add = T, quiet = T)
      mtext("Train", col = "blue", adj = 0.95, side = 1, line = 5, cex = 0.7)
      mtext("Test", col = "red", adj = 0.95, side = 1, line = 6, cex = 0.7)
    }
  }
}

Cheers, Ed