View source: R/predictMaxEnt.r
predictMaxEnt | R Documentation |
Takes a MaxEnt lambda
object or a MaxEnt object and returns raw or logistic predictions. Its output is the same as the function raster::predict(maxentModelObject, dataFrame)
or raster::predict(maxentModelObject, dataFrame, args='outputformat=raw')
(to within rounding error), and in fact those functions should be faster. However, this function does allow custom manipulations that those functions do not allow (e.g., permuting product features while leaving other features with the same variables intact). This function does not clamp predictions–beyond the range of the training data, it extends the prediction in the direction it was going (up/down/no change). The function is based on Peter D. Wilson's document "Guidelines for computing MaxEnt model output values from a lambdas file". The function has a special feature in that it allows you to permute single variables or combinations of variables in specific features before making predictions. This is potentially useful, for example, if you wanted to determine the relative importance of a quadratic feature for a particular variable in a Maxent model relative to the other features in the model. You can also permute values of a variable regardless of which features they appear in. For product features, you can implement the permutation before or after the values are multiplied together (before often makes for bigger differences in predictions).
predictMaxEnt( x, data, type = "cloglog", perm = NULL, permLinear = NULL, permQuad = NULL, permHinge = NULL, permThresh = NULL, permProd = NULL, permProdRule = NULL, ... )
x |
Either a Maxent lambda object or a Maxent model object |
data |
Data frame. Data to which to make predictions |
type |
Character. One of:
|
perm |
Character vector. Name(s) of variable to permute before calculating predictions. This permutes the variables for all features in which they occur. If a variable is named here, it overrides permutation settings for each feature featType. Note that for product features the variable is permuted before the product is taken. This permutation is performed before any subsequent permutations (i.e., so if both variables in a product feature are included in |
permLinear |
Character list. Names(s) of variables to permute in linear features before calculating predictions. Ignored if |
permQuad |
Names(s) of variables to permute in quadratic features before calculating predictions. Ignored if |
permHinge |
Character vector. Names(s) of variables to permute in forward/reverse hinge features before calculating predictions. Ignored if |
permThresh |
Character list. Names(s) of variables to permute in threshold features before calculating predictions. Ignored if |
permProd |
Character list. A list object of |
permProdRule |
Character. Rule for how permutation of product features is applied: |
... |
Extra arguments (not used). |
Numeric.
maxent
### model red-bellied lemurs data(mad0) data(lemurs) # climate data bios <- c(1, 5, 12, 15) clim <- raster::getData('worldclim', var='bio', res=10) clim <- raster::subset(clim, bios) clim <- raster::crop(clim, mad0) # occurrence data occs <- lemurs[lemurs$species == 'Eulemur rubriventer', ] occsEnv <- raster::extract(clim, occs[ , c('longitude', 'latitude')]) occsEnv <- as.data.frame(occsEnv) # need to do this for prediction later # background sites bg <- 2000 # too few cells to locate 10000 background points bgSites <- dismo::randomPoints(clim, 2000) bgEnv <- extract(clim, bgSites) # collate presBg <- rep(c(1, 0), c(nrow(occs), nrow(bgSites))) env <- rbind(occsEnv, bgEnv) env <- cbind(presBg, env) env <- as.data.frame(env) preds <- paste0('bio', bios) regMult <- 1:3 # default values are probably better, but these will be faster # calibrate MaxEnt model ent <- trainMaxEnt( data=env, resp='presBg', preds=preds, regMult=regMult, classes='lpq', verbose=TRUE ) # calibrate MaxNet model net <- trainMaxNet( data=env, resp='presBg', preds=preds, regMult=regMult, classes='lpq', verbose=TRUE ) # prediction rasters mapEnt <- predict(ent, clim, type='logistic') mapNet <- predict(clim, net, type='logistic') par(mfrow=c(1, 2)) plot(mapEnt, main='MaxEnt') points(occs[ , c('longitude', 'latitude')]) plot(mapNet, main='MaxNet') points(occs[ , c('longitude', 'latitude')]) # predictions to occurrences (dismo::predict(ent, occsEnv, args=c('outputformat=logistic'))) (enmSdm::predictMaxEnt(ent, occsEnv, type='logistic')) (c(predict(net, occsEnv, type='logistic'))) # note the differences between the tuning of the two models... # this is because maxnet() (used by trainMaxNet()) # uses an approximation: # (note maxnet() calculates hinges and thresholds differently # so we will turn them off) data(bradypus, package='maxnet') p <- bradypus$presence data <- bradypus[ , 2:3] # easier to inspect betas mn <- maxnet::maxnet(p, data, maxnet::maxnet.formula(p, data, classes='lpq')) mx <- dismo::maxent(data, p, args=c('linear=true', 'product=true', 'quadratic=true', 'hinge=false', 'threshold=false')) predMx <- dismo::predict(mx, data) predMn <- predict(mn, data, type='logistic') par(mfrow=c(1, 1)) plot(predMx, predMn) abline(0, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.