cannot turn off clamping with dismo predict() and response()

467 views
Skip to first unread message

Jamie M. Kass

unread,
Jan 27, 2017, 12:59:57 PM1/27/17
to Maxent
Just found this confusing (and potentially dangerous) anomaly with the R package dismo today. When you build a model with maxent() and set args="doclamp=false" or args="dontdoclamp", the output html shows the correct response curve and prediction raster, in that it extrapolates to values outside the training range, and does not clamp. However, when you input the model object into predict(), it clamps by default, even if you set args="doclamp=false" or args="dontdoclamp" for predict() as well. I could not figure out a way to force predict() to disable clamping. This is evident when using response(), which uses predict() with no extra parameters -- the response curves are exactly the same if you input a clamped model versus an unclamped model. If there is a way to disable clamping for predict(), then one can add a custom "fun" parameter to response() that disables clamping as well for the response curves.

I want to emphasize that the model output with maxent() runs just the way you'd expect -- it clamps when you leave the args as default, and it disables clamping when you do args="doclamp=false" or args="dontdoclamp". The output rasters are also correct. The problem here if you use the model object to make raster predictions or response curves with predict().

My question is, does anyone know to disable clamping when using predict()? I hope that Robert Hijmans, or someone else intimate with the dismo code, sees this and can comment.

Jamie Kass
PhD Candidate
City College of NYC 

Ahmed El-Gabbas

unread,
Feb 3, 2017, 1:34:31 PM2/3/17
to Maxent
Well-spotted Jamie,

I think there may be an error with the dismo:::predict() function. However, I tried a workaround, without the use of dismo package [R code attached].

Your feedback is welcome!
Ahmed

-----------------
Ahmed El-Gabbas
PhD candidate,
University of Freiburg
https://www.biom.uni-freiburg.de/mitarbeiter/El-Gabbas
Maxent_Clamping.R

Ahmed El-Gabbas

unread,
Feb 3, 2017, 1:54:10 PM2/3/17
to Maxent
line 27 should reads:
 "write.table(Model@lambdas, file = paste0(EnvFolder, "\\Lambdas.lambdas"), quote=F, row.names=F, col.names = FALSE)"


On Friday, 27 January 2017 18:59:57 UTC+1, Jamie M. Kass wrote:

Jamie M. Kass

unread,
Feb 14, 2017, 11:21:48 PM2/14/17
to Maxent
Ahmed,

Sorry for the late reply. Yes, your function does seem to be clamping and not clamping the right way. You managed this by calling maxent.jar directly and specifying the parameters, in a similar way to how dismo::maxent.predict() works. Did you discover exactly what was wrong with the dismo version? Why wasn't the doclamp=FALSE getting through?

The only thing this implementation lacks is some method for predicting new values in a data frame (for building response curves). This seems to only make rasters. Is there a way that anyone is able to do this without the help of Stephen Phillips or Robert Hijmans?

By the way, the difference between clamping / no clamping is even more stark in your example when you restrict the occurrence and background points spatially (e.g. lat > 0).

Thanks for the great work!


Jamie Kass
PhD Candidate
City College of NYC

Gonzalo Pinilla-Buitrago

unread,
Mar 14, 2017, 12:18:46 PM3/14/17
to Maxent
Hi Jamie,

I have the same problem with this argument in predict(), but it is not the only one, the args='extrapolate=false' doesn´t work too. In my case, I was trying to project to other time. To compare, I made two models in Maxent GUI, one with extrapolate and clamping activate, and other without these arguments. The results obtained in dismo R are the same to the Maxent GUI with activated options, so the arguments 'args=c("extrapolate=false","doclamp=false")' is not working in the function. Because, I really needed the projections rasters, the temporal "solution" was defining the output folder and the projection folders when I run maxent().

Let me know if you found a solution.
Gonzalo Pinilla

Jamie M. Kass

unread,
Mar 14, 2017, 12:25:41 PM3/14/17
to Maxent
Gonzalo,

So you are trying to make model predictions that are NA for predictor variable values outside the training range? Because that's what clamp=FALSE with extrapolate=FALSE would seem to do.

Jamie

Gonzalo Pinilla-Buitrago

unread,
Mar 14, 2017, 12:42:44 PM3/14/17
to Maxent
Jamie,

Yes, I only want the projections areas that correspond to the training range. So, I tried to use these arguments in predict() but didn't work. If you compare the output rasters with and without this arguments, they are the same. I also tried to used the rasters in ASCII format, but I obtained the same result.

Gonzalo

Julian Burgos

unread,
Sep 12, 2018, 10:02:57 AM9/12/18
to Maxent
Hi everyone,

I found myself dealing with the same issue after running a bunch of models with different settings (for comparison) and finding out that dismo's predict function ignores the doclap=false and the fadebyclamping=true arguments.  Does anybody has an update on this? 

thanks,

Julian


Jamie M. Kass

unread,
Sep 12, 2018, 11:19:53 AM9/12/18
to max...@googlegroups.com
This issue is still unresolved in dismo, but the maxnet.predict() function in the maxnet package does honor clamping, so if you want to make predictions that are not clamped, try maxnet.

Jamie

--
You received this message because you are subscribed to a topic in the Google Groups "Maxent" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/maxent/VUZu3ja_Wp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to maxent+un...@googlegroups.com.
To post to this group, send email to max...@googlegroups.com.
Visit this group at https://groups.google.com/group/maxent.
For more options, visit https://groups.google.com/d/optout.


--
-----------------------------------------------------------
Jamie M. Kass
PhD Candidate, Dept. of Biology
City College of New York, CUNY Graduate Center

Adam Smith

unread,
Sep 13, 2018, 11:01:45 AM9/13/18
to Maxent
In frustration with this issue I wrote my own predict function for maxent (not maxnet) model objects.  You're welcome to use it--it's slower than predict() in dismo, but it does clamp.  The function is called predictMaxEnt() and it's in the enmSdm package on GitHub which you can install on R using:

install.packages('devtools') # if you haven't done this already
library(devtools)
install_github('adamlilith/omnibus')
install_github('adamlilith/enmSdm')
# you may also need to install the "sp", "dismo", "raster", and other
# packages (all from CRAN), depending on the functions you wish to use

library(omnibus)
library(enmSdm)

Best,
Adam

Jamie M. Kass

unread,
Sep 20, 2018, 4:10:15 PM9/20/18
to max...@googlegroups.com
That's really great, Adam. Good to know there is an alternative that actually turns clamping off. Thanks!

Jamie
Reply all
Reply to author
Forward
0 new messages