[Biomod-commits] myBiomodModelEval in biomod2

Damien Georges damien.georges2 at gmail.com
Tue Jan 8 14:31:26 CET 2013


Dear Anne,

I guess the issue you have come from your cordinates data.frame. You 
have well defined the response vector by replacing all 0 by NA's to 
indicate that they are not "true absences" but only "potential 
absences". Then you mustn't remove the NA's coordinate from your 
coordinates..
I will add some extra checking to prevent from this kind of error.

Try to do something like :

--------------------R input---------------------------------------

#Load required data
Data <- read.table("BIOMOD_envSP_full_data.txt", h=T, sep="\t")
#Read species data file
Sp.data <- Data[, c(2:3, 34)]

### Fill 'NAs'
Sp.data[Sp.data==0] <- NA

#read environmental data
Env <- Data[, 4:33]

#Load the library
library(biomod2)

### definition of data

*myResp <- as.numeric(Sp.data[,"B_aeth"])**
**myRespCoord = Sp.data[, c('X', 'Y')] ## coordinates**
**myRespName = "B_aeth"*


#Format data to biomod2
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp, expl.var = Env,
                                      resp.xy = myRespCoord, resp.name = myRespName, PA.nb.rep = 1,
                                      PA.nb.absences = 10000, PA.strategy = 'random')
#Check input data
myBiomodData

#View the input data
plot(myBiomodData)

### Options definition
myBiomodOption <- BIOMOD_ModelingOptions(MAXENT = list(path_to_maxent.jar =
"C:\\Maxent\\", maximumiterations = 500), GBM = list(n.trees = 3000,
cv.folds = 5))


### Modelling
myBiomodModelOut <- BIOMOD_Modeling(myBiomodData, models =
c('MAXENT','GBM'), models.options = myBiomodOption, NbRunEval=1,
DataSplit=80, Yweights=NULL, VarImport=0, models.eval.meth =
c('TSS','ROC'), SaveObj = TRUE, rescal.all.models = TRUE)

#model evaluation
myBiomodModelEval <- getModelsEvaluations(myBiomodModelOut)
dimnames(myBiomodModelEval)
myBiomodModelEval

------------------R output------------------
> myBiomodModelEval
, , MAXENT, RUN1, PA1

     Testing.data  Cutoff Sensitivity Specificity
TSS        0.716 494.455      80.952        90.6
ROC        0.858 998.001      80.952        90.6

, , GBM, RUN1, PA1

     Testing.data  Cutoff Sensitivity Specificity
TSS        0.670 494.455      71.429        95.6
ROC        0.835 998.001      71.429        95.6

, , MAXENT, Full, PA1

     Testing.data  Cutoff Sensitivity Specificity
TSS        0.876 494.455       94.34       93.23
ROC        0.938 998.001       94.34       93.23

, , GBM, Full, PA1

     Testing.data  Cutoff Sensitivity Specificity
TSS        0.878 494.455      93.396       94.38
ROC        0.939 998.001      93.396       94.38

That seems to work well at least on my computer.

Hope that helps,

Best,

Damien.


On 07/01/2013 11:23, Anne Blach Overgaard wrote:
> Dear Damien/list
> I have just recently started using biomod2 (newest version with R2.15.2)
> instead of BIOMOD and I am still getting used to the new code. I have run
> into an issue I hope you can assist me with.
> Running biomod2 using the script below runs smoothly and I get no error
> messages. However, when I try to assess the evaluation of the different
> models I get the R output pasted below with NA's for all dimensions.
> With a data split of 80 surely some evaluation should be done or have I
> made a mistake in my script somewhere that I cannot seem to spot?
>
> Thanks,
>
> Anne
>
> PS I have the same issue whether I use the dataframe data as here or a
> rasterstack
>
>
>
> --------------------R input---------------------------------------
> #Load required data
> Data <- read.table("BIOMOD_envSP_full_data.txt", h=T, sep="\t")
> #Read species data file
> Sp.data <- Data[, c(2:3, 34)]
>
> ### Fill 'NAs'
> Sp.data[Sp.data==0] <- NA
>
> #read environmental data
> Env <- Data[, 4:33]
>
>
> #Load the library
> library(biomod2)
>
>
>
> ### definition of data
>
> myResp <- (Sp.data["B_aeth"])
> # get NAs id
> na.id <- which(is.na(Sp.data))
>
> myRespCoord = Sp.data[-na.id, c('X', 'Y')] ## coordinates of the
> presence-only data
> myRespName = "B_aeth"
>
>
> #Format data to biomod2
> myBiomodData <- BIOMOD_FormatingData(resp.var = myResp, expl.var = Env,
> resp.xy = myRespCoord, resp.name = myRespName, PA.nb.rep = 1,
> PA.nb.absences = 10000, PA.strategy = 'random')
>
> #Check input data
> myBiomodData
>
> #View the input data
> plot(myBiomodData)
>
> ### Options definition
> myBiomodOption <- BIOMOD_ModelingOptions(MAXENT = list(path_to_maxent.jar =
> "C:\\Maxent\\", maximumiterations = 500), GBM = list(n.trees = 3000,
> cv.folds = 5))
>
>
> ### Modelling
> myBiomodModelOut <- BIOMOD_Modeling(myBiomodData, models =
> c('MAXENT','GBM'), models.options = myBiomodOption, NbRunEval=1,
> DataSplit=80, Yweights=NULL, VarImport=0, models.eval.meth =
> c('TSS','ROC'), SaveObj = TRUE, rescal.all.models = TRUE)
>
> #model evaluation
> myBiomodModelEval <- getModelsEvaluations(myBiomodModelOut)
> dimnames(myBiomodModelEval)
> myBiomodModelEval
>
> ------------------R output------------------
>
>> myBiomodModelEval
> , , MAXENT, RUN1, PA1
>
>      Testing.data Cutoff Sensitivity Specificity
> TSS           NA     NA          NA          NA
> ROC           NA     NA          NA          NA
>
> , , GBM, RUN1, PA1
>
>      Testing.data Cutoff Sensitivity Specificity
> TSS           NA     NA          NA          NA
> ROC           NA     NA          NA          NA
>
> , , MAXENT, Full, PA1
>
>      Testing.data Cutoff Sensitivity Specificity
> TSS           NA     NA          NA          NA
> ROC           NA     NA          NA          NA
>
> , , GBM, Full, PA1
>
>      Testing.data Cutoff Sensitivity Specificity
> TSS           NA     NA          NA          NA
> ROC           NA     NA          NA          NA
> _______________________________________________
> Biomod-commits mailing list
> Biomod-commits at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/biomod-commits



More information about the Biomod-commits mailing list