0

I have a MaxEnt model implemented in dismo package. The package has the convenient function response to plot predictors' responses as the ones provided by the model html output, in R plotting style.

I would like to plot the predictor responses of the"single-predictor" models likewise (as the ones shown below in the html), either by adapting the response function or by directly accessing data, but I couldn't find a solution for either cases.

More specifically, I can find out where to retrieve the plotted values in the model object.

To be more clear, here below in blue the plots I'm referring to (from MaxEnt html output)

enter image description here

EDIT: here's a reproducible example

library(raster) 
library(dismo)

## create 5 dummy predictors layer and stack them
iterations <- 5
mn <- c(0:10)
stdev <- c(0:10)
preds <- list()
for(i in 1:iterations){
  xy <- matrix(rnorm(40000, mean=sample(mn, 1), sd=sample(stdev, 1)),200,200)
  preds[[i]] <- raster(xy, 8,9,45,46, crs="+proj=longlat +datum=WGS84")
}
preds_stack <- stack(preds)

## create random locations and random background points
ext <- raster(matrix(0,1,1), 8,9,45,46, crs="+proj=longlat +datum=WGS84")
ext <- as(ext, 'SpatialPolygons')
locations <- spsample(ext, 200, type='clustered') 
background <- spsample(ext, 2000, type='random') 

## run MaxEnt
argumemts <- c("-J", "-P", "askoverwrite=false", "threads=6")
mod <- maxent(x=preds_stack, p=locations, a=coordinates(background)[,1:2], args=argumemts)  
mod # opens html output
  • any reproducible example? – Matifou Oct 17 '17 at 19:04
1

Not sure whether this is what you are looking for, but: if you use response() specifying a single variable, the function will plot and invisibly return the x, y, data. Is that what you are looking for?

r <- response(mod, var="layer.1")
r

# recreate the plot:
plot(r, type="l", ylim=c(0,1), col=2)

If you want to look at the source code, check:

getMethod("response", "DistModel")
dismo:::.doResponse

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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