I am trying to use the SDM package to predict to a new area.
I have successfully calibrated by testing/ training the model on data for one location where the species occurs (lots of presence data + with background data) and want to project the prediction to another location where the ecology is similar. I am using the same environmental variables (predictors) although I have cropped them to fit the calibration area (Area A) and area of interest for the projection (Area B).
However I cannot seem to get the predict() function to work on a projection from Area A to Area B.
pr <- predict(model, newpredictors)
where for ‘model’ I have tried the output/ object saved from the predict() from Area A, and an object/ output from ensemble() of predictors and model output of Area A.
The ‘newpredictors’ is made of a new RasterStack of the same predictor variables used in Area A, but clipped to the area of Interest in Area B (they are Europe/ worldwide and Area A and Area B are subsets of this). I have tried to save to disk and re-import as a SpatRaster via rast() for both the outputs of ensemble() and predict() in Area A, and for ‘newpredictors’ stack in Area B. All files are SpatRaster or RasterStack originally.
But I get the error:
Error in UseMethod(“predict”) :
no applicable method for ‘predict’ applied to an object of class “data.frame”
I also tried to use the RasterStack of predictors I used in Area A and got (unsurprisingly! I was hitting desperate measures by this point):
Error in .generateWLP(x = object, newdata = newdata, w = id, species = species, :
the newdata does not contain some or all of the predictor variables required by the model…!
This may not be fully reproducible, but aware I could list my entire project if I tried to make an example. Given that the calibration (test/train) model on Area A produces a perfect output as expected, it is the projection that I am clearly missing something fundamental!
Many thanks