This tutorial will guide you to process spatial data and implement Maxent modeling in R. Therefore, you need to make sure necessary software/libraries are ready in your computer.
Step 1: install the list of software and libraries (adapted from data carpentry)
|Name||Type||Need||Install||Description and notes|
|R||software||Yes||Go to CRAN’s cloud download page and select the version for your operating system. Download the base subdirectory and install it on your computer.||Software environment for statistical and scientific computing|
|RStudio||software||Yes||Go to RStudio download page and select RStudio Desktop for your operating system. Download and install it on your computer.||Graphic User Interface (GUI) for R|
|Java JDK||software||Yes||Go to JAVA download page and select Java SE Development Kit 8u191 for your operating system. Download and install version x86 if your operating system is 32-bit, or use version x64 if your operating system is 64-bit. Read more about 32-bit vs. 64-bit.||A programing environmental to run Maxent modeling algorithm. This is different than Java (which you might already have installed on your computer)|
|raster||R package||Yes||Option 1: install packages from Rstudio interface.
Option 2: use install.packages() function in R terminal.
Option 3: run the following script in R terminal to install:
|for raster analysis|
|sp||R package||Yes||see above||for spatial analysis|
|rgdal||R package||Yes||see above||for spatial analysis|
|dismo||R package||Yes||see above||a collection of ENM/SDM tools, including a function to run Maxent.jar in R|
|rJava||R package||Yes||Note: in macOS, if you see error like this when loading rJava library:
error: unable to load shared object ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so’: Please run the following code in your terminal:
|An interface to Java|
|jsonlite||R package||Yes||see above||necessary for download data from GBIF|
|ENMeval||R package||Yes||see above||a collection of ENM/SDM tools, including a function to separate occurrences|
|Maxent||software||Yes||Install dismo package first, then
Option 1: manually download from this link and move Maxent.jar to the path where dismo package is installed, which can be obtained from this function
Option 2: run the following script in R terminal to download.
|Maxent modeling algorithm|
|GDAL||software||optional||Windows: do the installations through OSGeo4W.
macOS: run the following code.
Find more help via this link.
|Geospatial model for reading and writing a variety of formats; this is necessary if you want to install rgdal package from source code|
|PROJ.4||software||optional||see above||Coordinate reference system transformations; this is necessary if you want to install rgdal package from source code|
Step 2: test if you have successfully install all necessary software/packages:
2.1 Open RStudio
2.2 Load libraries from R terminal:
library("raster") library("dismo") library("rgdal") library("sp") library("ENMeval") library("rJava")
2.3 Run a simple Maxent model from R terminal:
# get predictor variables fnames <- list.files(path=paste(system.file(package="dismo"), '/ex', sep=''), pattern='grd', full.names=TRUE ) predictors <- stack(fnames) # file with presence points occurence <- paste(system.file(package="dismo"), '/ex/bradypus.csv', sep='') occ <- read.table(occurence, header=TRUE, sep=',')[,-1] # witholding a 20% sample for testing fold <- kfold(occ, k=5) occtest <- occ[fold == 1, ] occtrain <- occ[fold != 1, ] # fit model, biome is a categorical variable me <- maxent(predictors, occtrain, factors='biome') # see the maxent results in a browser: me