trainMaxEnt | R Documentation |
This function calculates the "best" Maxent model using AICc across all possible combinations of a set of master regularization parameters and feature classes. The best model has the lowest AICc, with ties broken by number of features (fewer is better), regularization multiplier (higher better), then finally the number of coefficients (fewer better). The function can return the best model (default), a list of models created using all possible combinations of feature classes and regularization multipliers, and/or a data frame with tuning statistics for each model. Models in the list and in the data frame are sorted from best to worst. The function requires the maxent
jar file (see Details).
trainMaxEnt( data, resp = names(data)[1], preds = names(data)[2:ncol(data)], regMult = c(seq(0.5, 5, by = 0.5), 7.5, 10), classes = "default", testClasses = TRUE, dropOverparam = TRUE, anyway = TRUE, out = "model", forceLinear = TRUE, jackknife = FALSE, arguments = NULL, scratchDir = NULL, cores = 1, verbose = FALSE, ... )
data |
Data frame or matrix. Contains a column indicating whether each row is a presence (1) or background (0) site, plus column(s) for environmental predictor(s). |
resp |
Character or integer. Name or column index of response variable. Default is to use the first column in |
preds |
Character list or integer list. Names of columns or column indices of predictors. Default is to use the second and subsequent columns in |
regMult |
Numeric vector. Values of the master regularization parameters (called |
classes |
Character list. Names of feature classes to use (either |
testClasses |
Logical. If |
dropOverparam |
Logical, if |
anyway |
Logical. Same as |
out |
Character or character vector. Indicates type of value returned. Values can be |
forceLinear |
Logical. If |
jackknife |
Logical. If |
arguments |
|
scratchDir |
Character. Directory to which to write temporary files. Leave as NULL to create a temporary folder in the current working directory. |
cores |
Integer >= 1. Number of cores to use. Default is 1. |
verbose |
Logical. If |
... |
Extra arguments. Not used. |
This function is a wrapper for maxent()
. That function relies on a maxent jar
file being placed into the folder ./library/dismo/java
. See maxent
for more details. The maxent()
function creates a series of files on disc for each model. This function assumes you do not want those files, so deletes most of them. However, there is one that cannot be deleted and the normal ways of changing its permissions in R
do not work. So the function simply writes over that file (which is allowed) to make it smaller. Regardless, if you run many models your temporary directory (argument scratchDir
) can fill up and require manual deletion.
If out = 'model'
this function returns an object of class MaxEnt
. If out = 'tuning'
this function returns a data frame with tuning parameters, log likelihood, and AICc for each model tried. If out = c('model', 'tuning'
then it returns a list object with the MaxEnt
object and the data frame.
Warren, D.L. and S.N. Siefert. 2011. Ecological niche modeling in Maxent: The importance of model complexity and the performance of model selection criteria. Ecological Applications 21:335-342.
maxnet
, maxent
, trainMaxNet
### 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 <- raster::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.