SDM Example - Biomod Formatting Error with multiple presence absence draws

Use the built in data from the biomod2 help screen, start with the data exactly as its cut and paste from the help.

require(biomod2)
# species occurrences
DataSpecies <- read.csv(system.file("external/species/mammals_table.csv", package = "biomod2"), 
    row.names = 1)
head(DataSpecies)
##   X_WGS84 Y_WGS84 ConnochaetesGnou GuloGulo PantheraOnca PteropusGiganteus
## 1   -94.5      82                0        0            0                 0
## 2   -91.5      82                0        1            0                 0
## 3   -88.5      82                0        1            0                 0
## 4   -85.5      82                0        1            0                 0
## 5   -82.5      82                0        1            0                 0
## 6   -79.5      82                0        1            0                 0
##   TenrecEcaudatus VulpesVulpes
## 1               0            0
## 2               0            0
## 3               0            0
## 4               0            0
## 5               0            0
## 6               0            0

# the name of studied species
myRespName <- "GuloGulo"

# the presence/absences data for our species
myResp <- as.numeric(DataSpecies[, myRespName])

# the XY coordinates of species data
myRespXY <- DataSpecies[, c("X_WGS84", "Y_WGS84")]


# Environmental variables extracted from BIOCLIM (bio_3, bio_4, bio_7,
# bio_11 & bio_12)
myExpl = stack(system.file("external/bioclim/current/bio3.grd", package = "biomod2"), 
    system.file("external/bioclim/current/bio4.grd", package = "biomod2"), system.file("external/bioclim/current/bio7.grd", 
        package = "biomod2"), system.file("external/bioclim/current/bio11.grd", 
        package = "biomod2"), system.file("external/bioclim/current/bio12.grd", 
        package = "biomod2"))

# 1. Formatting Data
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp, expl.var = myExpl, resp.xy = myRespXY, 
    resp.name = myRespName, )
## 
## -=-=-=-=-=-=-=-=-=-=-=-= GuloGulo Data Formating -=-=-=-=-=-=-=-=-=-=-=-=
## 
## > No pseudo absences selection !
##       ! No data has been set aside for modeling evaluation
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

myBiomodData
## 
## -=-=-=-=-=-=-=-=-=-=-=-=-= 'BIOMOD.formated.data' -=-=-=-=-=-=-=-=-=-=-=-=-=
## 
## sp.name =  GuloGulo
## 
##   661 presences,  1827 true absences and  0 undifined points in dataset
## 
## 
##   5 explanatory variables
## 
##       bio3           bio4            bio7           bio11       
##  Min.   :10.2   Min.   :   72   Min.   : 54.5   Min.   :-447.7  
##  1st Qu.:21.2   1st Qu.: 2641   1st Qu.:186.0   1st Qu.:-184.3  
##  Median :35.0   Median : 6682   Median :306.2   Median :  24.2  
##  Mean   :40.3   Mean   : 7358   Mean   :310.9   Mean   :  -2.6  
##  3rd Qu.:56.4   3rd Qu.:11752   3rd Qu.:424.6   3rd Qu.: 196.3  
##  Max.   :92.0   Max.   :22314   Max.   :718.0   Max.   : 283.0  
##      bio12     
##  Min.   :   0  
##  1st Qu.: 276  
##  Median : 563  
##  Mean   : 854  
##  3rd Qu.:1201  
##  Max.   :5431  
## 
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
plot(myBiomodData)

plot of chunk unnamed-chunk-1

That looks great!

Now just change the options to

PA.nb.rep = 1, PA.nb.absences = 2000, PA.strategy = 'random')

# species occurrences 1. Formatting Data
showE <- tryCatch(BIOMOD_FormatingData(resp.var = myResp, expl.var = myExpl, 
    resp.xy = myRespXY, resp.name = myRespName, PA.nb.rep = 2, PA.nb.absences = 2000, 
    PA.strategy = "random"), error = function(e) print(e))
## 
## -=-=-=-=-=-=-=-=-=-=-=-= GuloGulo Data Formating -=-=-=-=-=-=-=-=-=-=-=-=
## 
##       ! No data has been set aside for modeling evaluation
##    > Pseudo Absences Selection checkings...
##    > random pseudo absences selection
##    > Pseudo absences are selected in explanatory variables
##    > All availables cells have been selected ( 0 pseudo absences selected )<simpleError: evaluation nested too deeply: infinite recursion / options(expressions=)?>

showE
## <simpleError: evaluation nested too deeply: infinite recursion / options(expressions=)?>

I also tried to make this example more like my own use case, by having only presence, and psuedoabsence info that i want biomod to draw from

# Set all absences to psuedo absence background points
myResp[myResp == 0] <- NA

head(myResp)
## [1] NA  1  1  1  1  1

# Run data formatting.
showE <- tryCatch(BIOMOD_FormatingData(resp.var = myResp, expl.var = myExpl, 
    resp.xy = myRespXY, resp.name = myRespName, PA.nb.rep = 2, PA.nb.absences = 2000, 
    PA.strategy = "random"), error = function(e) print(e))
## 
## -=-=-=-=-=-=-=-=-=-=-=-= GuloGulo Data Formating -=-=-=-=-=-=-=-=-=-=-=-=
## 
##       ! No data has been set aside for modeling evaluation
##    > Pseudo Absences Selection checkings...
##    > random pseudo absences selection
##    > All availables cells have been selected ( 1827 pseudo absences selected )<simpleError: evaluation nested too deeply: infinite recursion / options(expressions=)?>

My last idea was there was too many psuedoabsence compared to the dataset, drop number of psuedoabsences to 100

length(myResp)
## [1] 2488

showE <- tryCatch(BIOMOD_FormatingData(resp.var = myResp, expl.var = myExpl, 
    resp.xy = myRespXY, resp.name = myRespName, PA.nb.rep = 2, PA.nb.absences = 100, 
    PA.strategy = "random"), error = function(e) print(e))
## 
## -=-=-=-=-=-=-=-=-=-=-=-= GuloGulo Data Formating -=-=-=-=-=-=-=-=-=-=-=-=
## 
##       ! No data has been set aside for modeling evaluation
##    > Pseudo Absences Selection checkings...
##    > random pseudo absences selection<simpleError: evaluation nested too deeply: infinite recursion / options(expressions=)?>