cjcarlson / embarcadero

🌲🌉 Species distribution models with Bayesian additive regression trees
49 stars 11 forks source link

predict() gives completely flat prediction at 0.5 #28

Closed VirginiaMorera closed 1 year ago

VirginiaMorera commented 3 years ago

I am having some issues with the predict function that I'm not sure are a bug or me doing something wrong.

I ran a model in a cluster, saved the result of bart.step() as an RDS file, and then opened it locally. Everything seems good, this is how the loaded object looks:

> class(calbor.sdm)
[1] "bart"
> summary(calbor.sdm)
Call:  bart all.cov[, step.model] all.cov[, "pres"] TRUE 

Predictor list: 
 bati chla_var logchla_lag3 sal sst sst_grad 

Area under the receiver-operator curve 
AUC = 0.8937647 

Recommended threshold (maximizes true skill statistic) 
Cutoff =  0.519118 
TSS =  0.6287537 
Resulting type I error rate:  0.16072 
Resulting type II error rate:  0.2105263 

which I don't hate, and the plot looks like this imagen

However, when I try to predict using

CB_prediction <- embarcadero::predict2.bart(object = calbor.sdm2,   #make sure I'm getting embarcadero's predict
                         x.layers = predictors_original,
                         quantiles =c(0.025, 0.975),
                         # splitby = 20,   #Doesn't work with or without this
                         quiet = F)

I get a stack of rasters with all cells == 0.5, see:

> CB_prediction
class      : RasterStack 
dimensions : 266, 242, 64372, 3  (nrow, ncol, ncell, nlayers)
resolution : 0.4986111, 0.4986111  (x, y)
extent     : -64.84722, 55.81667, -52.825, 79.80556  (xmin, xmax, ymin, ymax)
crs        : NA 
names      : layer.1, layer.2, layer.3 
min values :     0.5,     0.5,     0.5 
max values :     0.5,     0.5,     0.5 

that looks like this imagen

I've tried tweaking the options of the predict function, but nothing seemed to work.

The cluster (where I ran the model) works with R version 3.6, while I'm running in my laptop Windows x64 (where I'm predicting and plotting) R version 4.1.1.

Thanks for the help!

cjcarlson commented 1 year ago

See: https://github.com/cjcarlson/embarcadero/issues/29#issuecomment-1445479364