This page provides an outline of the workflow to create species distribution/range models for BIEN.
Text in purple describes a read operation, while text in red describes a write operation.
R Script: ComputerRageAreasNEW.r
Requires:
- R
- R library raster
- R library dismo
- R library sp
- R library rgdal
- Maxent.jar – from http://www.cs.princeton.edu/~schapire/maxent/
Workflow:
- Set working directory base path
- Set output directories from working directory
- Set background raster layer for clipping raster output to continental margin
- Record start time
- Read a CSV file, i.e. “Abies balsamea UTM.csv” into a data frame
- Define the data frame as spatial points and assign our UTM projection
- Create a convex hull vector polygon from UTM points
- Get the spatial extent of the convex hull – sets the spatial extent of the bounding box
- Compute latitudinal and longitudinal range (in meters)
- Create a vector polyon of the bounding box area
- Create a latitudinal band (min and max latitudinal extent plus min and max continental longitude extent)
- Create raster layers of the points, convex hull, bounding box and latitude extent polygons
- Clip the rasters using the continental background raster to remove ocean, etc.
- Get cell counts for points convex hull, bounding box and latitude extent raster layers (clipped versions)
- Calculate area from cell counts
- Write the resulting raster layers to disk:
- points
- convex hull
- bounding box
- latitude extent
- Record the results in a matrix to hold the statistics
- Write the matrix to a CSV file as part 1 - optional
- Initiate a maxent run for all 19 Bioclim environmental layers
- Prepare a stack of environmental layers for maxent
- Send species name, points, background raster, environmental layers, model type and output directory variables to Maxent function (CreateSDMFunctionNEW.r) to run maxent and return a data frame of results.
- Initiate a maxent run for 19 Spatial filter layers
- Prepare a stack of environmental layers for maxent
- Send species name, points, background raster, environmental layers, model type and output directory variables to Maxent function (CreateSDMFunctionNEW.r) to run maxent and return a data frame of results.
- Initiate a maxent run for all 19 Bioclim environmental layers + 19 spatial filter layers
- Prepare a stack of environmental layers for maxent
- Send species name, points, background raster, environmental layers, model type and output directory variables to Maxent function (CreateSDMFunctionNEW.r) to run maxent and return a data frame of results.
- Record the end time
- Combine matrices from part 1 and individual maxent runs into a large matrix
- Write full matrix of all results to a CSV file
- Finished
-- New Function --
R Script: CreateSDMFunctionNEW.r
R function that receives input from ComputerRageAreasNEW.r, runs maxent and records resulting raster layers and statistics. Returns a matrix of results.
Requires:
- R library rJava
Workflow:
- Perform Kfold partitioning to withhold 20% of the points for testing
- Split points into training points and testing points
- Run maxent to fit the training points to a model
- Use the resulting model to predict to entire dataset
- Write the resulting maxent raster layer to a file
- Evaluate the resulting maxent model
- Create random point sample of background variables and use with testing points to evaluate model
- Obtain evaluation statistics
- Number of presences
- Number of absences
- AUC
- Correlation
- Kappa score at maximum kappa
- Obtain true/false positive/negative totals from the confusion table
- True positive
- False positive
- True negative
- False negative
- Calculate sensitivity
- Calculate specificity
- Calculate overall accuracy (correct/total)
- Record all returned model thresholds
- Get the threshold at
- a) maximum training sensitivity and specificity
- b) equal training sensitivity and specificity, and
- c) maximum kappa
- Get the threshold at
- Resample the maxent raster layer to a new binary raster layer of cells that equal or exceed the maximum training sensitivity and specificity threshold value
- Write the binary thresholded raster layer to disk
- Get cell count and area of binary thresholded raster layer
- Record all maxent result statistics to a matrix for returning to the main function
- Write maxent statistics to CSV file (Part 2) - optional
- Write all returned thresholds to CSV file (for later use in a separate analysis not included here)
- Return matrix to main function
-- End of Document --