Search code examples
rmodelgbmdismobiomod2

Errors: incorrect number of dimensions when using BIOMOD_Modeling()


I recently start learning how to use biomod2 package, with latest version, 4.2-3. I try to fit a model using the GBM algorithm in BIOMOD_Modeling() from the package biomod2. I've checked the help file and googled for the error. However, the error seems to be a general error, so that I can't figure out what happened when carry out the function. I Expected the function can build a correct model.

For species data, I subset species Acacia confusa from vegetation database, with 1 means presence and 0 means absence. There are totally 7796 plots. I have checked that there is no any NA. If need more details about the data, please let me know.

> dim(test_spe)
[1] 7796    1
>
> head(test_spe)
# A tibble: 6 x 1
  `Acacia confusa`
             <dbl>
1                0
2                0
3                0
4                0
5                0
6                1

For environmental data, there is a mean annual temperature (MAT) for each plot.

> dim(test_env)
[1] 7796    1
>
> head(test_env)
       MAT
1 19.08279
2 19.08279
3 19.08279
4 20.02513
5 19.08279
6 17.25201

Next, I prepare data and settings for the modeling.

> data4biomod = BIOMOD_FormatingData(
+   resp.var = test_spe,  # Presence absence data, can only be one species
+   expl.var = test_env,  # Environmental variable
+   resp.name = "Acacia.confusa"  # Name of the modeled species
+ )

-=-=-=-=-=-=-=-=-=-=-=-=-=-= Acacia.confusa Data Formating -=-=-=-=-=-=-=-=-=-=-=-=-=-=

> No pseudo absences selection !
      ! No data has been set aside for modeling evaluation
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> settings4biomod = BIOMOD_ModelingOptions()  # Use the default settings

Last, the error occurs when I fit the model.

> biomod = BIOMOD_Modeling(
+   bm.format = data4biomod,  # Data used to build model
+   modeling.id = "testing",  # Name of the output model
+   models = c("GBM"),  # Algorithms
+   bm.options = settings4biomod,  # Settings for algorithms
+   nb.rep = 1,  # How many times to repeat the algorithms
+   data.split.perc = 100,  # Percentages for cross-validation, 100 means no cv
+ )

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Build Single Models -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Checking Models arguments...
Warning in .BIOMOD_Modeling.check.args(bm.format, modeling.id, models, bm.options,  :
  The models will be evaluated on the calibration data only (nb.rep=0 and no independent data) 
     It could lead to over-optimistic predictive performances.


Creating suitable Workdir...

    > Automatic weights creation to rise a 0.5 prevalence


-=-=-=-=-=-=-=-=-=-=-=-=-= Acacia.confusa Modeling Summary -=-=-=-=-=-=-=-=-=-=-=-=-=

 1  environmental variables ( MAT )
Number of evaluation repetitions : 1
Models selected : GBM 

Total number of model runs: 1 

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


-=-=-=- Run :  Acacia.confusa_allData 


-=-=-=--=-=-=- Acacia.confusa_allData_allRun 

Model=Generalised Boosting Regression 
     2500 maximum different trees and  3  Fold Cross-Validation
    > GBM modeling...CV: 1 
Error in x[i.train, , drop = TRUE][i, , drop = FALSE] : 
  incorrect number of dimensions
Error in h(simpleError(msg, call)) : 
  在為 'predict' 函式選擇方法時評估 'object' 引數發生錯誤: object 'model.bm' not found 

*** inherits(g.pred,'try-error')
   ! Note :  Acacia.confusa_allData_allRun_GBM failed!

! All models failed

The same data can be used for GAM and GLM algorithms in BIOMOD_Modeling().

Whole code as below (no raw data):

data4biomod = BIOMOD_FormatingData(
  resp.var = test_spe,  # Presence absence data, can only be one species
  expl.var = test_env,  # Environmental variable
  resp.name = "Acacia.confusa"  # Name of the modeled species
)

settings4biomod = BIOMOD_ModelingOptions()  # Use the default settings

biomod = BIOMOD_Modeling(
  bm.format = data4biomod,  # Data used to build model
  modeling.id = "testing",  # Name of the output model
  models = c("GBM"),  # Algorithms
  bm.options = settings4biomod,  # Settings for algorithms
  nb.rep = 1,  # How many times to repeat the algorithms
  data.split.perc = 100,  # Percentages for cross-validation, 100 means no cv
)

Solution

  • GAM algorithms in biomod2 package can't deal with the data with only one explained variable. The problem can be solved by downloading the package released by @raptin!!

    For more details, please check the issue on GitHub.