0

Similar question was answered here; however, this problem is a bit different for which I cannot apply that solution. I have fitted maxent using site-with-data format. The problem is I cannot project the fitted model. The output of m1 in the path D:/maxent looks fine. I suspect this two error (below) is related with rJava, but I don't know the solution. Please see my codes below:

> m1 <- maxent(x = d, p = id, path = "D:/maxent", 
             args = c("-P", "noautofeature", "nolinear", "noquadratic", "nothreshold", 
                      "noproduct", "betamultiplier=1", "replicates=10", "crossvalidate"))

# here d is a dataframe containing 11213 rows and 20 predictor columns (with numeric values), id is a vector containing numeric values of 1 and 0 (representing species presence and absence)
Loading required namespace: rJava
> plot(m1, xlim=c(0,100))
Error in as.double(y) : 
  cannot coerce type 'S4' to vector of type 'double'

> ras <- raster("E:/bio12.tif") # raster to project the fitted model 'm1'

> pred.m1 <- raster::predict(m1, ras)
Error in .local(object, ...) : missing layers (or wrong names)

Here is the properties of raster file

> ras
class       : RasterLayer 
dimensions  : 4292, 4936, 21185312  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 112.8917, 154.025, -43.75833, -7.991667  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : E:/Predictors_grasshoppers/selected.predictors/bio12.tif 
names       : bio12 
values      : 79, 7625  (min, max)

Update: I have tried using single quote in m1 and the problem is still there.

> m2 <- maxent(x = d, p = id, path = 'D:/PhD related/Historic climate data Australia/maxent2', 
             args = c('-P', 'noautofeature', 'nolinear', 'noquadratic', 'nothreshold', 
                      'noproduct', 'betamultiplier=1', 'replicates=10', 'crossvalidate'))
Tiny_hopper
  • 380
  • 1
  • 4
  • 15
  • What are the files present in `path = "D:/maxent"` folder? Please show that. – UseR10085 Feb 03 '20 at 05:33
  • These are files common output of maxent model (total 92 items: 1 folder containing figures and others are just file). Previously I ran the similar model and had no problem and produced similar files as well. – Tiny_hopper Feb 03 '20 at 05:50
  • I mean to say that you show the input names used in the `maxent` model. – UseR10085 Feb 03 '20 at 05:52
  • Thank you. I am updating my question again. – Tiny_hopper Feb 03 '20 at 05:54
  • Your input contains 20 predictor columns but during predict, you are using only one variable. You should try to predict it on a rasterstack of all the 20 predictor variables with same names as that of inputs. – UseR10085 Feb 03 '20 at 06:29
  • Thank you. The problem here is I have collected these predictor values from rasters of different years. For example, I have six rainfall predictors from 252 rasters (21 years monthly observation). This is similar is for temperature datasets. – Tiny_hopper Feb 03 '20 at 06:40

1 Answers1

0

Following the comment of @Bappa Das I found the solution. To project maxent fitted model into geographic space one should use a raster stack (not a single raster) containing variables that were used during the model fitting process. The order and name of predictors in the raster stack should be same as they were in fitted model.

Tiny_hopper
  • 380
  • 1
  • 4
  • 15