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.
85 stars 22 forks source link

Help with BIOMOD_PresenceOnly - Can biomod calculate continous boyce index? #285

Closed tongruiju closed 1 year ago

tongruiju commented 1 year ago

Dear Team,

I have used Biomod to make my predictions. I now need to evaluate the predicted maps using the continuous Boyce index. I am wondering if there is a way to do this using Biomod.

Best, Ruiju

rpatin commented 1 year ago

Dear Ruiju, Thank you for reporting :pray You can calculate the Boyce index with BIOMOD_PresenceOnly:

# Evaluate models with Boyce index and MPA
myBiomodPO <- BIOMOD_PresenceOnly(bm.mod = myBiomodModelOut,
                                  bm.em = myBiomodEM)
myBiomodPO

# Evaluate models with Boyce index and MPA (using background data)
myBiomodPO <- BIOMOD_PresenceOnly(bm.mod = myBiomodModelOut,
                                  bm.em = myBiomodEM, 
                                  bg.env = values(myExpl))
myBiomodPO

_Note that the function BIOMOD_PresenceOnly will disappear in next biomod2 version (eta end of summer) and calculations of MPA and Boyce Index will be fully integrated within BIOMOD_Modeling as other evaluation metrics._ Best, Rémi

tongruiju commented 1 year ago

Dear Rémi, Thanks a lot for your response. As far as I know the Boyce index is different to the Continous Boyce Index. I wonder if the Boyce index calculated by biomod is the Continous Boyce Index?

Best regards, Ruiju

rpatin commented 1 year ago

Dear Ruiju, Happy to help ! It is the same thing. You can check ecospat documentation or the following reference for more informations:

Hirzel, A. H., Le Lay, G., Helfer, V., Randin, C., and Guisan, A. 2006. Evaluating the ability of habitat suitability models to predict species presences. Ecological Modelling, 199(2), 142-152

Best regards, Rémi

tongruiju commented 1 year ago

Hi Rémi,

I see the distinction between the Boyce index and the continious Boyce index. Please refer to the following paragraph from (Hirzel et al., 2006). The main shortcoming of the Boyce index is its sensitivity to the number of suitability classes b and to their boundaries (Boyce et al., 2002; personal observations). To fix this problem, we derived a new evaluator based on a “moving window” of width W (say W= 0.1) instead of fixed classes. Computation starts with a first class covering the suitability range [0,W] whose P/E ratio is plotted against the average suitability value of the class, W/2. Then, the moving window is shifted from a small amount upwards and the P/E is plotted again. This operation is repeated until the moving window reaches the last possible range [1 −W, 1]. This provides a smooth P/E curve, on which a “continuous Boyce index” Bcont(W) is computed.

So, how is the Boyce index of biomod2 calculated? If it is calculated using a specific number of suitability classes then it is Boyce index. If it is calcalated based on a “moving window” of width, then it is continous Boyce index.

Best, Ruiju

rpatin commented 1 year ago

Hi Ruiju,

biomod2 calculate the Boyce index based on ecospat.boyce from package ecospat. Given that its documentation mention Hirzel et al. 2006, which was published in a collaboration with ecospat team, I suppose they calculate the continuous Boyce Index. If you want further information I suggest asking the question to ecospat team directly.

Best, Rémi

tongruiju commented 1 year ago

Hi Rémi,

Thanks very much for your assistant. From my understanding, it is more accurate to use background data for calculating the Boyce index. However, since my dataset is large, it is very time-consuming to calculate using the provided codes:

myBiomodPO <- BIOMOD_PresenceOnly(bm.mod = myBiomodModelOut,
                                  bm.em = myBiomodEM, 
                                  bg.env = values(myExpl)

I am wondering if it is possible to use a certain number of random selected background points instead of the entire background. If so, I would like to know how to modify the code and what format the extracted environmental variables of the selected background points should be. Thank you very much in advance.

Best, Ruiju

rpatin commented 1 year ago

Hi Ruiju, You can provide BIOMOD_PresenceOnly with a data.frame containing a subset of the environmental data. Here is the way to go (given that you work with terra and spatRaster):

library(terra)
n.sample <- 100 # adjust the sample size to suit your needs
myExpl.subsampled.df <- spatSample(myExpl, size = n.sample, na.rm = TRUE)
myBiomodPO <- BIOMOD_PresenceOnly(bm.mod = myBiomodModelOut,
                                  bm.em = myBiomodEM, 
                                  bg.env = myExpl.subsampled.df)

Best regards, Rémi

riyapakhre commented 6 months ago

Hii, I've performed sdm using MaxEnt software and now need to calculate the Continuous Boyce Index. I am planning to use ecospat.Boyce for the purpose, however, I'm confused about the inputs required. Any kind of help shall be welcomed. Thanks!

MayaGueguen commented 6 months ago

Hello there,

Please note that this is biomod2 help page :eyes:

We are indeed using in our code the ecospat.boyce from the ecospat package. As it was the only function together with ecospat.mpa we were using from this package, we included the code directly in one of our file with reference to simplify dependencies. The code is visible here. Note that (unless it changed since August 2022), it should be the same as the code from the function ecospat.boyce from the ecospat package.

As indicated in the comments, the function requires as inputs the predicted values for all points (parameter fit) and the predicted values only for points that were observed as presences (parameter obs).

Hope it helps,

Maya