2

I used "dismo" package in R, and ran a build a maxent model. Now I want to extract the residuals from the model in order to run a Moran I test later. But I got an error. The code was like:

xm<-maxent(pridictors, p=sdmdata, factors="landuse")
sdmresiduals<-cbind(sdmdata,resid(xm))

And the error appearred:

Error: $ operator not defined for this S4 class

I don't understand what S4 class is. When I tried to have a look at the correlation between variables, using "car" package in R

vif(xm)

The same error happened.

How do I solve this problem?

1
  • 1
    This makes no sense, MaxEnt does not return residuals as it is nonparametric in nature. Commented Sep 3, 2019 at 19:10

1 Answer 1

1

Only half an answer: maxent() returns an object of the class MaxEnt. The fact that this is an S4-type object doesn't matter much here, but if you want top know more about that you can read on here. The actual "problem" is that the MaxEnt class does not provide a method for the generic residuals() function (resid() is just a shortcut for residuals()). I other words: resid() does not know what to do with xm.

resid(xm) is probably looking for xm$residuals, but that does not exist because MaxEnt objects do not contain a $residuals slot. In fact, MaxEnt objects do not contain any residuals at all, so if you want them you'll have to calculate them youself somehow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.