I am using Maxent function in dismo package to create some species distribution models.
Normally this works:
single_model <- maxent(predictors, presence, args=c('jackknife=TRUE', 'randomseed=FALSE',"randomtestpoints=25"), path=output)
evaluate.model <- evaluate(presence1, background1, single_model, predictors)
but when I create this model with replicates
rep_model <- maxent(predictors, presence, args=c('replicates=5', 'jackknife=TRUE', 'randomseed=FALSE'), path=output)
evaluate function doesn't work. It gives an error
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'raster' for signature '"numeric"'
Any ideas why? or how to solve it?
Here is the reproducible code:
r=raster(ncol=20,nrow=20)
r1=r
r2=r
r3=r
r1[]= 1:5
r2[]= 1:ncell(r)
r3[]= 1:20
r.stack= stack(r1,r2,r3)
p=randomPoints(r1,50)
single_model <- maxent(r.stack, p, args=c('jackknife=TRUE', 'randomseed=FALSE',"randomtestpoints=25"))
r4=r
r5=r
r6=r
r4[]= 30:40
r5[]= 1:ncell(r)
r6[]= 2:40
r.stack2= stack(r4,r5,r6)
p1=randomPoints(r1,50)
b1 <- randomPoints(r.stack2, 50)
evaluate.model <- evaluate(p1, b1, single_model, r.stack)
rep_model <- maxent(r.stack, p, args=c('replicates=5', 'jackknife=TRUE', 'randomseed=FALSE'))
evaluate.model2 <- evaluate(p1, b1, rep_model, r.stack)
Funny, I found the solution right after I posted here. I could't find the answer online so, I'll post it here for anyone who has the same problem could solve it.
rep_model@models[[1]]
with two brackets, subsetting works. For each model, one can use the evaluate function then average it.