Package 'ENMTools'

Title: Analysis of Niche Evolution using Niche and Distribution Models
Description: Constructing niche models and analyzing patterns of niche evolution. Acts as an interface for many popular modeling algorithms, and allows users to conduct Monte Carlo tests to address basic questions in evolutionary ecology and biogeography. Warren, D.L., R.E. Glor, and M. Turelli (2008) <doi:10.1111/j.1558-5646.2008.00482.x> Glor, R.E., and D.L. Warren (2011) <doi:10.1111/j.1558-5646.2010.01177.x> Warren, D.L., R.E. Glor, and M. Turelli (2010) <doi:10.1111/j.1600-0587.2009.06142.x> Cardillo, M., and D.L. Warren (2016) <doi:10.1111/geb.12455> D.L. Warren, L.J. Beaumont, R. Dinnage, and J.B. Baumgartner (2019) <doi:10.1111/ecog.03900>.
Authors: Dan Warren [aut, cre] , Russell Dinnage [aut]
Maintainer: Dan Warren <[email protected]>
License: GPL-2
Version: 1.1.3
Built: 2024-11-10 06:04:18 UTC
Source: https://github.com/danlwarren/enmtools

Help Index


Takes an enmtools.species object and a set of environment layers, and adds the environmental predictor values to the occurrence data. Typically not called by the user directly. Code modified from Elith and Hijmans SDM with R tutorial

Description

Takes an enmtools.species object and a set of environment layers, and adds the environmental predictor values to the occurrence data. Typically not called by the user directly. Code modified from Elith and Hijmans SDM with R tutorial

Usage

add.env(species, env, verbose = TRUE)

Arguments

species

An enmtools.species or enmtools.clade object

env

A raster stack of environmental variables

verbose

Controls printing of progress messages

Value

An enmtools.species object with environmental data attached to it.


Assert that the extra packages needed for an ENMTools function are installed and available

Description

Triggers an error if any of the extra packages required for an ENMTools function are not available.

Usage

assert.extras(funs = NULL)

Arguments

funs

character vector of ENMTools function names to install extra dependencies for. If 'NULL', extras for all ENMTools functions will be installed.

Value

None, this function is used for its side-effects

Examples

if(check.extras("enmtools.gam")) {
  assert.extras("enmtools.gam")
}

Takes a set of points, a buffer radius, a buffer type, and a mask and returns either a raster, a polygon, or background points representing the species background. Code modified from Elith and Hijmans SDM with R tutorial

Description

Takes a set of points, a buffer radius, a buffer type, and a mask and returns either a raster, a polygon, or background points representing the species background. Code modified from Elith and Hijmans SDM with R tutorial

Usage

background.buffer(
  points,
  buffer.width,
  buffer.type = "circles",
  mask = NA,
  return.type = "raster",
  n = 1000
)

Arguments

points

A two column data frame with X and Y coordinates

buffer.width

Radius for circular buffers to draw around points, for buffer.type = circular. If buffer.type = "convhull", denotes the amount to which the initial polygon should be buffered. It's worth noting that this argument may in some cases be treated as map units (e.g., lat and long), but in other caess may be treated as meters. If you're getting weird behavior, you might try changing the units you're using to specify buffer.width.

buffer.type

Which method to use for buffering species occurrence points. Currently accepts "circles" and "convhull".

mask

A raster to use as a mask for trimming the buffer if the return type is "raster" or "points"

return.type

What type of object to return. Can be "raster", "polygon", or "points".

n

Sample size for number of background points to return, for return.type = "points".

Value

Either a raster, a polygon, or a data frame of points representing the species background.


Takes a set of points, a buffer radius, a sample size, and a mask and returns randomly sampled points from within that buffer radius. Code modified from Elith and Hijmans SDM with R tutorial

Description

NOTE: This function has been replaced by background.buffer.

Usage

background.points.buffer(points, radius, n, mask)

Arguments

points

A two column data frame with X and Y coordinates

radius

Radius for circular buffers to draw around points, in meters.

n

Sample size for number of background points to return

mask

A raster to use as a mask for drawing points

Value

A data frame of points drawn at random from circular buffers around the occurrence points.


Takes a set of points, a buffer radius, and a mask and returns a raster based on that buffer radius. Code modified from Elith and Hijmans SDM with R tutorial

Description

NOTE: This function has been replaced by background.buffer.

Usage

background.raster.buffer(points, radius, mask)

Arguments

points

A two column data frame with X and Y coordinates

radius

Radius for circular buffers to draw around points, in meters.

mask

A raster to use as a mask

Value

A raster object with values of 1 in every grid cell falling within the buffer.

Examples

library(ENMTools)
background.raster.buffer(iberolacerta.clade$species$cyreni$presence.points, 100000, euro.worldclim)

Takes a set of points and a buffer radius, and returns a polygon. Code modified from Elith and Hijmans SDM with R tutorial

Description

NOTE: This function has been replaced by background.buffer.

Usage

background.shape.buffer(points, radius)

Arguments

points

A two column data frame with X and Y coordinates

radius

Radius for circular buffers to draw around points, in meters.

Value

A polygon shapefile.


background.test Conduct a background test (also called a similarity test), as described in Warren et al. 2008. This test can either be run as an asymmetric test (species.1 vs background of species.2) or as a symmetric test (background of species.1 vs background of species.2). For GLM, Bioclim, and Domain models the replicates will be constructed from the background points supplied for each species. For Maxent, the replicates will be constructed from the range rasters stored in the enmtools.species objects.

Description

background.test Conduct a background test (also called a similarity test), as described in Warren et al. 2008. This test can either be run as an asymmetric test (species.1 vs background of species.2) or as a symmetric test (background of species.1 vs background of species.2). For GLM, Bioclim, and Domain models the replicates will be constructed from the background points supplied for each species. For Maxent, the replicates will be constructed from the range rasters stored in the enmtools.species objects.

Usage

background.test(
  species.1,
  species.2,
  env,
  type,
  f = NULL,
  nreps = 99,
  test.type = "asymmetric",
  nback = 1000,
  bg.source = "default",
  low.memory = FALSE,
  rep.dir = NA,
  verbose = FALSE,
  clamp = TRUE,
  ...
)

Arguments

species.1

An emtools.species object from which presence points (asymmetric) or background (symmetric) will be sampled.

species.2

An enmtools.species object from which background will be sampled.

env

A SpatRaster object containing environmental data

type

The type of model to construct, currently accepts "glm", "mx", "bc", "gam", or "dm"

f

A function to use for model fitting. Only required for GLM models at the moment.

nreps

Number of replicates to perform

test.type

Controls whether the background test will be "symmetric" or "asymmetric"

nback

Number of background points for models

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

low.memory

When set to TRUE, replicate models are written to disc instead of being stored in the output object. Replicate models stored in the output object contain paths to the replicate models on disk instead of the rasters themselves.

rep.dir

Directory for storing replicate models when low.memory is set to TRUE. If not specified, the working directory will be used.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

Controls whether empirical and replicate models should be clamped to the environment space used for training.

...

Additional arguments to be passed to model fitting functions.

Value

results A list containing replicates, models for the empirical data, and summary statistics and plots.

Examples

cyreni <- iberolacerta.clade$species$cyreni
monticola <- iberolacerta.clade$species$monticola
cyreni$range <- background.raster.buffer(cyreni$presence.points, 100000, euro.worldclim)
monticola$range <- background.raster.buffer(monticola$presence.points, 100000, euro.worldclim)
background.test(cyreni, monticola, env = euro.worldclim, type = "glm",
f = pres ~ bio1 + bio12, nreps = 10)

calc.B1, Calculates standardized version of Levins (1968) B1 measure of niche breadth given a vector of suitabilities

Description

calc.B1, Calculates standardized version of Levins (1968) B1 measure of niche breadth given a vector of suitabilities

Usage

calc.B1(x)

Arguments

x

A numeric vector

Value

B1 A calculation of Levins (1968) B1 metric

Examples

calc.B1(c(1, .001, .001))

calc.B2, Calculates standardized version of Levins (1968) B2 measure of niche breadth given a vector of suitabilities

Description

calc.B2, Calculates standardized version of Levins (1968) B2 measure of niche breadth given a vector of suitabilities

Usage

calc.B2(x)

Arguments

x

A numeric vector

Value

B2 A calculation of Levins (1968) B2 metric

Examples

calc.B2(c(1, .001, .001))

Takes an emtools.species object and adds background points if they're missing. Looks for range raster first, then goes for environmental layers.

Description

Takes an emtools.species object and adds background points if they're missing. Looks for range raster first, then goes for environmental layers.

Usage

check.bg(
  species,
  env = NA,
  nback = 1000,
  bg.source = "default",
  verbose = FALSE,
  bias = NA
)

Arguments

species

An enmtools.species object

env

A SpatRaster containing environmental data.

nback

Number of background points to generate, if any

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

bias

A SpatRaster representing estimated relative sampling bias. Used when bg.source is either "range" or "env".

Value

An enmtools.species object with background points.


Checking for complians of an enmtools.clade object

Description

Checking for complians of an enmtools.clade object

Usage

check.clade(this.clade)

Arguments

this.clade

An enmtools.clade object

Value

An enmtools.clade object with appropriate formatting.

Examples

check.clade(iberolacerta.clade)

Automating some basic tasks for using a raster stack for modeling. Checks rasters for same extent and resolution, and sets values in each layer to NA if there is an NA in any other layer.

Description

Automating some basic tasks for using a raster stack for modeling. Checks rasters for same extent and resolution, and sets values in each layer to NA if there is an NA in any other layer.

Usage

check.env(env, verbose = FALSE)

Arguments

env

A stack of environmental rasters

verbose

Controls printing of progress messages

Value

A raster stack.

Examples

check.env(euro.worldclim)

Check that the extra packages needed for an ENMTools function are installed and available

Description

Check that the extra packages needed for an ENMTools function are installed and available

Usage

check.extras(funs = NULL)

Arguments

funs

character vector of ENMTools function names to install extra dependencies for. If 'NULL', extras for all ENMTools functions will be installed.

Value

Logical, 'TRUE' if all required extra packages are available, 'FALSE' otherwise

Examples

check.extras("enmtools.gam")

Checking compliance for an object of class enmtools.species.

Description

Checking compliance for an object of class enmtools.species.

Usage

check.species(this.species, env = NA, trim.dupes = FALSE)

Arguments

this.species

An enmtools.species object to be checked.

env

Environmental rasters that will be used for modeling. If provided to check.species, ENMTools will remove occurrence points that have NA values for any layer in env.

trim.dupes

Controls whether to trim duplicate occurrence points from the presence data. Defaults to FALSE, which leaves duplicates in place. Alternatives are "exact", which will remove points with the same lat/long as another point, or "grid", which will trim data so that there is at most one point per grid cell for the rasters in env, and centers those points in the cells.

Value

An enmtools.species object with appropriate formatting.

Examples

check.species(iberolacerta.clade$species$monticola)

Takes an emtools.model object and a set of environment layers and clamps the environment layers so that no variable falls outside of the range available in the training data.

Description

Takes an emtools.model object and a set of environment layers and clamps the environment layers so that no variable falls outside of the range available in the training data.

Usage

clamp.env(model, env)

Arguments

model

An enmtools.model object. Alternatively the analysis.df component of an enmtools.model object.

env

A SpatRaster of environmental data.

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

monticola.gam <- enmtools.gam(iberolacerta.clade$species$monticola, euro.worldclim[[c(1,5,9,13)]])
euro.clamped <- clamp.env(monticola.gam, euro.worldclim)
clamped.prediction <- predict(monticola.gam, euro.clamped)
terra::plot(clamped.prediction$suitability - monticola.gam$suitability)

Takes a list of enmtools.species objects and combines them into a single enmtools.species object

Description

Takes a list of enmtools.species objects and combines them into a single enmtools.species object

Usage

combine.species(species.list)

Arguments

species.list

List of enmtools.species objects that you want to combine together

Value

An enmtools.species object with the occurrence data, names, and range rasters for the species list combined into one.

Examples

combine.species(iberolacerta.clade$species)

Takes a an ENMTools clade object and a vector of species names. Drops the species from the tree and removes data from the clade object.

Description

Takes a an ENMTools clade object and a vector of species names. Drops the species from the tree and removes data from the clade object.

Usage

drop.species(clade, species)

Arguments

clade

An ENMTools clade object

species

A name or vector of names of species within the enmtools.clade object.

Value

An enmtools.clade object with the provided species dropped both from the tree and from the set of enmtools.species objects.

Examples

if(requireNamespace("ape", quietly = TRUE)) {
    new.clade <- drop.species(iberolacerta.clade, c("cyreni", "monticola"))
}

Takes an overlap matrix and a tree and runs permutation tests to determine the statistical significance of the relationship between overlap and time

Description

Takes an overlap matrix and a tree and runs permutation tests to determine the statistical significance of the relationship between overlap and time

Usage

enmtools.aoc(
  clade,
  env = NULL,
  overlap.source,
  nreps = 100,
  f = NULL,
  overlap.matrix = NULL,
  metric = "D",
  ...
)

Arguments

clade

An enmtools.clade object containing species data and a phylogeny

env

Environmental layers for use when overlap is calculated using niche models.

overlap.source

The source of the overlaps to calculate. Choices are "bc", "dm", "gam", "glm", "mx", "range", and "point"

nreps

A number of reps to do

f

The model to be used for GLM and GAM comparisons

overlap.matrix

A matrix of overlaps to use, for option overlap.source = "matrix"

metric

The overlap metric to use. For ENM sources, this can be any combination of "D", "I", "cor", "env.D", "env.I", and "env.cor". for range and point overlap this argument is ignored.

...

Arguments to be passed to modeling functions for ENM-based overlaps.

Value

A list containing a data frame of coefficients from the empirical regression of overlap on time along with the coefficients from all Monte Carlo replicates, along with plots and p values for the accompanying statistical tests.


Takes an emtools.species object with presence and background points, and builds a Bioclim model

Description

Takes an emtools.species object with presence and background points, and builds a Bioclim model

Usage

enmtools.bc(
  species,
  env = NA,
  test.prop = 0,
  report = NULL,
  overwrite = FALSE,
  nback = 1000,
  env.nback = 10000,
  rts.reps = 0,
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

report

Optional name of an html file for generating reports

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

nback

Number of background points for models. In the case of bioclim models these are only used for evaluation.

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

...

Arguments to be passed to bioclim()

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

enmtools.bc(iberolacerta.clade$species$monticola, env = euro.worldclim)

Takes an emtools.model object, and reformats it to run through the CalibratR package, calculates Continuous Boyce Index, and runs a Hosmer-Lemeshow goodness-of-fit test. Can either do a full CalibratR run or just return ECE/MCE statistics and plots.

Description

Takes an emtools.model object, and reformats it to run through the CalibratR package, calculates Continuous Boyce Index, and runs a Hosmer-Lemeshow goodness-of-fit test. Can either do a full CalibratR run or just return ECE/MCE statistics and plots.

Usage

enmtools.calibrate(
  model,
  recalibrate = FALSE,
  cuts = 11,
  env = NA,
  n.background = 10000,
  recal.methods = c(1, 2, 3, 4),
  ...
)

Arguments

model

An enmtools.model object

recalibrate

When TRUE, does a full CalibratR "calibrate" run to recalibrate the model. When FALSE, just returns metrics and plots measuring calibration of the model as is.

cuts

The number of bins to split suitability scores into for calculating calibration.

env

A set of environment layers to be used for optional env space metrics

n.background

Number of background points to be used for env space metrics

recal.methods

Numeric or vector specifying which methods the CalibratR package should use for recalibration. 1=hist_scaled, 2=hist_transformed, 3=BBQ_scaled, 4=BBQ_transformed. Option 5 is disabled by default due to errors.

...

Further arguments to be passed to CalibratR's "calibrate" function.

Value

An enmtools.calibrate object containing calibration and classificaction plots, metrics of model calibration, and (optionally) versions of the model that were recalibrated using various methods.

Examples

#install.extras(repos='http://cran.us.r-project.org')
monticola.glm <- enmtools.glm(iberolacerta.clade$species$monticola,
                              env = euro.worldclim,
                              f = pres ~ bio1 + bio9,
                              test.prop = 0.3)
if(check.extras("enmtools.calibrate")) {
  enmtools.calibrate(monticola.glm)
}

Defining a class for enmtools.clade. Each clade gets:

Description

Defining a class for enmtools.clade. Each clade gets:

Usage

enmtools.clade(species = NA, tree = NA)

save.enmtools.clade(x, ...)

load.enmtools.clade(x, ...)

Arguments

species

A list of enmtools.species objects

tree

A tree showing the relationships between the species

x

Path to an enmtools.species file

...

Other arguments passed to R's load function

Value

An enmtools.clade object, either empty or containing a formatted version of the data that was passed into the function.

Functions

  • save.enmtools.clade(): Save an ENMTools clade object

  • load.enmtools.clade(): Load an ENMTools clade object


Takes an emtools.species object with presence and background points, and builds a Domain model

Description

Takes an emtools.species object with presence and background points, and builds a Domain model

Usage

enmtools.dm(
  species,
  env = NA,
  test.prop = 0,
  report = NULL,
  nback = 1000,
  env.nback = 10000,
  overwrite = FALSE,
  rts.reps = 0,
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

report

Optional name of an html file for generating reports

nback

Number of background points for models. In the case of Domain, these are only used for evaluation.

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

...

Arguments to be passed to domain()

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

enmtools.dm(iberolacerta.clade$species$monticola, env = euro.worldclim)

enmtools.ecospat.bg, Runs an ecospat background/similarity test using enmtool.species objects.

Description

enmtools.ecospat.bg, Runs an ecospat background/similarity test using enmtool.species objects.

Usage

enmtools.ecospat.bg(
  species.1,
  species.2,
  env,
  nreps = 99,
  layers = NULL,
  test.type = "symmetric",
  th.sp = 0,
  th.env = 0,
  R = 100,
  nback = 1000,
  bg.source = "default",
  verbose = FALSE,
  ...
)

Arguments

species.1

An enmtools.species object

species.2

An enmtools.species object

env

A set of environmental layers

nreps

The number of pseudoreplicates to perform

layers

A vector of length 2 containing the names of the layers to be used. If no layer names are provided and there are more than two layers in env, enmtools will perform a pca and use the top two layers from that.

test.type

Symmetric or asymmetric test. An asymmetric test is bguivalent to the "one.sided" option in the ecospat documentation, while a symmetric one would be two-sided.

th.sp

Quantile of species densities used as a threshold to exclude low species density values. See documentation for ecospat.grid.clim.dyn.

th.env

Quantile of environmental densities across study sites used as threshold to exclude low environmental density values. See documentation for ecospat.grid.clim.dyn.

R

Resolution of the grid. See documentation for ecospat.grid.clim.dyn.

nback

Number of background points to use for density calculations.

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

...

Further arguments to be passed to check.bg

Value

A list containing the ecospat output kernel density estimates for each species and their background, as well as the results of hypothesis tests and their accompanying plots.

Examples

#install.extras(repos='http://cran.us.r-project.org')
monticola <- iberolacerta.clade$species$monticola
cyreni <- iberolacerta.clade$species$cyreni
if(check.extras("enmtools.ecospat.bg")) {
  enmtools.ecospat.bg(monticola, cyreni, euro.worldclim[[1:2]], nback = 500)
}

enmtools.ecospat.id, Runs an ecospat identity test using enmtool.species objects.

Description

enmtools.ecospat.id, Runs an ecospat identity test using enmtool.species objects.

Usage

enmtools.ecospat.id(
  species.1,
  species.2,
  env,
  nreps = 99,
  layers = NULL,
  th.sp = 0,
  th.env = 0,
  R = 100,
  nback = 1000,
  bg.source = "default",
  verbose = FALSE
)

Arguments

species.1

An enmtools.species object

species.2

An enmtools.species object

env

A set of environmental layers

nreps

The number of pseudoreplicates to perform

layers

A vector of length 2 containing the names of the layers to be used. If no layer names are provided and there are more than two layers in env, enmtools will perform a pca and use the top two layers from that.

th.sp

Quantile of species densities used as a threshold to exclude low species density values. See documentation for ecospat.grid.clim.dyn.

th.env

Quantile of environmental densities across study sites used as threshold to exclude low environmental density values. See documentation for ecospat.grid.clim.dyn.

R

Resolution of the grid. See documentation for ecospat.grid.clim.dyn.

nback

Number of background points to use for density calculations.

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

Value

A list containing the ecospat output kernel density estimates for each species and their background, as well as the results of hypothesis tests and their accompanying plots.

Examples

#install.extras(repos='http://cran.us.r-project.org')
monticola <- iberolacerta.clade$species$monticola
cyreni <- iberolacerta.clade$species$cyreni
if(check.extras("enmtools.ecospat.id")) {
  enmtools.ecospat.id(monticola, cyreni, euro.worldclim[[1:2]], nback = 500)
}

Takes an emtools.species object with presence and background points, and builds a gam

Description

Takes an emtools.species object with presence and background points, and builds a gam

Usage

enmtools.gam(
  species,
  env,
  f = NULL,
  test.prop = 0,
  k = 4,
  nback = 1000,
  env.nback = 10000,
  report = NULL,
  overwrite = FALSE,
  rts.reps = 0,
  weights = "equal",
  gam.method = "REML",
  gam.select = TRUE,
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

f

Standard gam formula

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

k

Dimension of the basis used to represent the smooth term. See documentation for s() for details.

nback

Number of background points to draw from range or env, if background points aren't provided

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

report

Optional name of an html file for generating reports

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

weights

If this is set to "equal", presences and background data will be assigned weights so that the sum of all presence points weights equals the sum of all background point weights. Otherwise, weights are not provided to the model.

gam.method

Defaults to restricted maximum likelihood to facilitate predictor selection, but if you want to use another method you can pass anything here that gam's "method" argument understands.

gam.select

Controls whether gam algorithm attempts to optimize smoothness and reduce model complexity. See help("gam.selection") for details.

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

...

Arguments to be passed to gam()

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

if(requireNamespace("mgcv", quietly = TRUE)) {
    enmtools.gam(iberolacerta.clade$species$monticola, env = euro.worldclim, f = pres ~ bio1 + bio9)
}

Takes an enmtools.species object with presence and background points, and builds a GLM

Description

Takes an enmtools.species object with presence and background points, and builds a GLM

Usage

enmtools.glm(
  species,
  env,
  f = NULL,
  test.prop = 0,
  eval = TRUE,
  nback = 1000,
  env.nback = 10000,
  report = NULL,
  overwrite = FALSE,
  rts.reps = 0,
  weights = "equal",
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  step = FALSE,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

f

Standard GLM formula

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

eval

Determines whether model evaluation should be done. Turned on by default, but moses turns it off to speed things up.

nback

Number of background points to draw from range or env, if background points aren't provided

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

report

Optional name of an html file for generating reports

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

weights

If this is set to "equal", presences and background data will be assigned weights so that the sum of all presence points weights equals the sum of all background point weights. Otherwise, weights are not provided to the model.

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

step

Logical determining whether to do stepwise model selection or not

...

Arguments to be passed to glm()

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

enmtools.glm(iberolacerta.clade$species$monticola, env = euro.worldclim, f = pres ~ bio1 + bio9)

THIS FUNCTION IS CURRENTLY DISABLED. Takes an emtools.species object and environmental layers, and constructs a hypervolume using the R package hypervolume

Description

THIS FUNCTION IS CURRENTLY DISABLED. Takes an emtools.species object and environmental layers, and constructs a hypervolume using the R package hypervolume

Usage

enmtools.hypervolume(
  species,
  env,
  samples.per.point = 10,
  reduction.factor = 0.1,
  method = "gaussian",
  verbose = FALSE,
  clamp = TRUE,
  ...
)

Arguments

species

An enmtools.species object

env

A stack of environmental rasters

samples.per.point

To be passed to hypervolume_gaussian

reduction.factor

To be passed to hypervolume_project

method

Method for constructing hypervolumes, defaults to "gaussian"

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

...

Extra parameters to be passed to hypervolume_gaussian

Value

An enmtools hypvervolume object containing a hypervolume object, a raster of suitability scores, the species name, and the occurrence data frame.

Examples

#install.extras(repos='http://cran.us.r-project.org')
env <- euro.worldclim[[c(1,8,12,17)]]
if(requireNamespace("hypervolume", quietly = TRUE)) {
    monticola.hv <- enmtools.hypervolume(iberolacerta.clade$species$monticola, env = env)
}

Takes an emtools.species object with presence and background points, and builds a maxent model

Description

Takes an emtools.species object with presence and background points, and builds a maxent model

Usage

enmtools.maxent(
  species,
  env,
  test.prop = 0,
  nback = 1000,
  env.nback = 10000,
  report = NULL,
  overwrite = FALSE,
  rts.reps = 0,
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

nback

Number of background points to draw from range or env, if background points aren't provided

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

report

Optional name of an html file for generating reports

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

...

Arguments to be passed to maxent()

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

if(check.extras("enmtools.maxent")) {
    ## maxent is not working on some platforms so use try()
    try(enmtools.maxent(iberolacerta.clade$species$monticola, env = euro.worldclim))
}

Takes an emtools.species object with presence and background points, and builds a random forest model

Description

Takes an emtools.species object with presence and background points, and builds a random forest model

Usage

enmtools.rf(
  species,
  env,
  f = NULL,
  test.prop = 0,
  eval = TRUE,
  nback = 1000,
  env.nback = 10000,
  report = NULL,
  overwrite = FALSE,
  rts.reps = 0,
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

f

A formula for fitting the model

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

eval

Determines whether model evaluation should be done. Turned on by default, but moses turns it off to speed things up.

nback

Number of background points to draw from range or env, if background points aren't provided

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

report

Optional name of an html file for generating reports

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

...

Arguments to be passed to rf()

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

enmtools.rf(iberolacerta.clade$species$monticola, env = euro.worldclim, nback = 500)

Takes an emtools.species object with presence and background points, and builds a random forest model using the 'probability mode' in package 'ranger'

Description

Takes an emtools.species object with presence and background points, and builds a random forest model using the 'probability mode' in package 'ranger'

Usage

enmtools.rf.ranger(
  species,
  env,
  f = NULL,
  test.prop = 0,
  eval = TRUE,
  nback = 1000,
  env.nback = 10000,
  report = NULL,
  overwrite = FALSE,
  rts.reps = 0,
  bg.source = "default",
  verbose = FALSE,
  clamp = TRUE,
  corner = NA,
  bias = NA,
  ...
)

Arguments

species

An enmtools.species object

env

A SpatRaster of environmental data.

f

A formula for fitting the model

test.prop

Proportion of data to withhold randomly for model evaluation, or "block" for spatially structured evaluation.

eval

Determines whether model evaluation should be done. Turned on by default, but moses turns it off to speed things up.

nback

Number of background points to draw from range or env, if background points aren't provided

env.nback

Number of points to draw from environment space for environment space discrimination metrics.

report

Optional name of an html file for generating reports

overwrite

TRUE/FALSE whether to overwrite a report file if it already exists

rts.reps

The number of replicates to do for a Raes and ter Steege-style test of significance

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

When set to TRUE, clamps the environmental layers so that predictions made outside the min/max of the training data for each predictor are set to the value for the min/max for that predictor. Prevents the model from extrapolating beyond the min/max bounds of the predictor space the model was trained in, although there could still be projections outside the multivariate training space if predictors are strongly correlated.

corner

An integer from 1 to 4. Selects which corner to use for "block" test data. By default the corner is selected randomly.

bias

An optional raster estimating relative sampling effort per grid cell. Will be used for drawing background data.

...

Arguments to be passed to ranger

Value

An enmtools model object containing species name, model formula (if any), model object, suitability raster, marginal response plots, and any evaluation objects that were created.

Examples

enmtools.rf.ranger(iberolacerta.clade$species$monticola, env = euro.worldclim, nback = 500)

Defining a class for enmtools.species.

Description

Each species gets:

Usage

enmtools.species(
  range = NA,
  presence.points = NA,
  background.points = NA,
  species.name = NA,
  models = NA
)

save.enmtools.species(x, ...)

load.enmtools.species(x, ...)

Arguments

range

A raster or SpatialPolygon with the actual range they occur in

presence.points

A data frame with sampled localities

background.points

A data frame with absence/pseudoabsence/background localities

species.name

A character vector with the species name

models

A list of models that are made for the species, which will be stuffed in there as we go along to pass the check. This is used by internal enmtools functions to make sure the necessary data is present before processing anything.

x

Path to an enmtools.species file

...

Other arguments passed to R's load function

Value

Returns an enmtools.species object, either empty or populated with the parameter values that were passed into the function.

Functions

  • save.enmtools.species(): Save an ENMTools species object

  • load.enmtools.species(): Load an ENMTools species object


Takes an enmtools.model object, and performs variable importance analyses on it using methods from the vip package

Description

Takes an enmtools.model object, and performs variable importance analyses on it using methods from the vip package

Usage

enmtools.vip(
  model,
  metric = "roc_auc",
  nsim = 10,
  method = "permute",
  verbose = FALSE,
  ...
)

Arguments

model

An enmtools.model object

metric

The metric to use for measuring how variables affect model predictions

nsim

The number of simulations to be run for method "permute"

method

A character string or vector containing any combination of "model", "permute", "shap", or "firm". For details on what these mean, see the vip package help.

verbose

Controls printing of messages

...

Further arguments to be passed to vip's "vi" functions.

Value

An enmtools.vip object

Examples

#install.extras(repos='http://cran.us.r-project.org')
monticola.glm <- enmtools.glm(iberolacerta.clade$species$monticola,
                              env = euro.worldclim,
                              test.prop = 0.3)
if(check.extras("enmtools.vip")) {
  enmtools.vip(monticola.glm)
}

Calculates breadth of a model in environment space using latin hypercube sampling

Description

Calculates breadth of a model in environment space using latin hypercube sampling

Usage

env.breadth(model, env, tolerance = 1e-04, max.reps = 10, chunk.size = 1e+05)

Arguments

model

An enmtools.model object or a model object that can be projected using the predict() function

env

A raster, raster stack of environmental data, or a list of minima and maxima for the environmental space to evaluate models over.

tolerance

How close do successive overlap metrics have to be before we decide we're close enough to the final answer

max.reps

Maximum number of attempts that will be made to find suitable starting conditions

chunk.size

How many combinations of environmental variables to try at a time. If your niche breadth in environment space is small, increasing this value may help you get a result.

Value

A list containing the environmental space version of the B2 metric and a plot of B2 estimates as a function of sample size, used as a convergence diagnostic.

Examples

cyreni <- iberolacerta.clade$species$cyreni
cyreni.glm <- enmtools.glm(cyreni, euro.worldclim, test.prop = 0.2,
f = pres ~ bio1 + bio12, nback = 500)
env.breadth(cyreni.glm,  euro.worldclim)

Calculates evaluation metrics (AUC, etc.) using latin hypercube sampling in environment space

Description

Calculates evaluation metrics (AUC, etc.) using latin hypercube sampling in environment space

Usage

env.evaluate(
  species,
  model,
  env,
  bg.source = "background",
  n.background = 10000,
  test.eval = FALSE,
  verbose = FALSE,
  ...
)

Arguments

species

An enmtools.species object

model

An enmtools.model object or a model that can be projected using the predict() function of dismo

env

A SpatRaster of environmental data.

bg.source

Determines whether minima and maxima of the environment space should be picked using the environment layers or the background points.

n.background

The number of background points to sample from the environment space.

test.eval

When set to "true", env.evaluate evaluates the test data stored in the model object instead of the training data.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

...

Arguments to be passed to othfer functions

Value

A dismo evaluate object measuring the performance of model predictions in environment space.

Examples

cyreni <- iberolacerta.clade$species$cyreni
cyreni.glm <- enmtools.glm(cyreni, euro.worldclim, test.prop = 0.2,
f = pres ~ bio1 + bio12, nback = 500)
env.evaluate(cyreni, cyreni.glm,  euro.worldclim)

Calculates overlap between models in environment space using latin hypercube sampling

Description

Calculates overlap between models in environment space using latin hypercube sampling

Usage

env.overlap(
  model.1,
  model.2,
  env,
  tolerance = 0.001,
  max.reps = 10,
  cor.method = "spearman",
  chunk.size = 1e+05,
  recal.model.1 = NA,
  recal.model.2 = NA,
  verbose = FALSE
)

Arguments

model.1

An enmtools.model object model object that can be projected using the predict() function

model.2

Another enmtools.model object or other model object that can be projected using the predict() function

env

A raster, raster stack of environmental data, or a list of minima and maxima for the environmental space to evaluate models over

tolerance

How close do successive overlap metrics have to be before we decide we're close enough to the final answer

max.reps

Maximum number of attempts that will be made to find suitable starting conditions

cor.method

Which method to use for calculating correlations between models

chunk.size

How many combinations of environmental variables to try at a time. If your niche breadth in environment space is small, increasing this value may help you get a result.

recal.model.1

Optional. The output of enmtools.recalibrate for model 1, which needs to have been run with "recalibrate = TRUE".

recal.model.2

Optional. The output of enmtools.recalibrate for model 2, which needs to have been run with "recalibrate = TRUE".

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

Value

A list of values measuring the overlap between models in environment space, as well as some plots depicting change of the estimates as a function of how many samples were used, which are included as a sort of convergence diagnostic.

Examples

cyreni <- iberolacerta.clade$species$cyreni
monticola <- iberolacerta.clade$species$monticola
cyreni.glm <- enmtools.glm(cyreni, euro.worldclim, f = pres ~ bio1 + bio12, nback = 500)
monticola.glm <- enmtools.glm(monticola, euro.worldclim, f = pres ~ bio1 + bio12, nback = 500)
env.overlap(cyreni.glm, monticola.glm, euro.worldclim)

Worldclim data for Europe

Description

This is a fairly low-resolution set of Worldclim layers for Europe to be used in demonstrating ENMTools functions.

Usage

euro.worldclim

Format

A SpatRaster object with 19 worldclim layers.


Find the extra packages needed for an ENMTools function

Description

Find the extra packages needed for an ENMTools function

Usage

find.extras(funs = NULL)

Arguments

funs

character vector of ENMTools function names to install extra dependencies for. If 'NULL', extras for all ENMTools functions will be installed.

Value

A character vector with the names of extra packages required by 'funs'

Examples

find.extras("enmtools.calibrate")

Find the extra packages needed for an ENMTools function that are currently missing (not available)

Description

Find the extra packages needed for an ENMTools function that are currently missing (not available)

Usage

find.extras.missing(funs = NULL)

Arguments

funs

character vector of ENMTools function names to install extra dependencies for. If 'NULL', extras for all ENMTools functions will be installed.

Value

A character vector with the names of extra packages required by 'funs' that are currently not available

Examples

find.extras.missing("enmtools.calibrate")

Takes two emtools.species objects with range rasters, calculates overlap between them as in Fitzpatrick and Turelli 2006. This metric divides the area of overlap between two species ranges by the smaller of the two areas of the species' individual ranges. It therefore ranges from 0 (no overlap) to 1 (ranges are the same or the smaller species' range is contained entirely within the larger).

Description

Takes two emtools.species objects with range rasters, calculates overlap between them as in Fitzpatrick and Turelli 2006. This metric divides the area of overlap between two species ranges by the smaller of the two areas of the species' individual ranges. It therefore ranges from 0 (no overlap) to 1 (ranges are the same or the smaller species' range is contained entirely within the larger).

Usage

geog.range.overlap(x, y)

Arguments

x

An enmtools.species object containing a range raster

y

An enmtools.species object containing a range raster

Value

A numeric value measuring range overlap.

Examples

cyreni <- iberolacerta.clade$species$cyreni
monticola <- iberolacerta.clade$species$monticola
cyreni$range <- background.raster.buffer(cyreni$presence.points, 100000, euro.worldclim)
monticola$range <- background.raster.buffer(monticola$presence.points, 100000, euro.worldclim)
geog.range.overlap(cyreni, monticola)

Takes an emtools.species object and environmental layers, and constructs a hypervolume using the R package hypervolume

Description

Takes an emtools.species object and environmental layers, and constructs a hypervolume using the R package hypervolume

Usage

hypervolume.overlap(
  species.1,
  species.2,
  env = NA,
  reduction.factor = 0.1,
  ...
)

Arguments

species.1

An enmtools.species or enmtools.hypervolume object

species.2

An enmtools.species or enmtools.hypervolume object

env

A stack of environmental rasters, required when enmtools.species objects are passed

reduction.factor

Passed to hypervolume functions

...

Extra parameters to be passed to enmtools.hypervolume

Value

A list containing a set of hypervolume objects and the overlap that was measured between them.

Examples

#install.extras(repos='http://cran.us.r-project.org')
mont <- iberolacerta.clade$species$monticola
cyr <- iberolacerta.clade$species$cyreni
env <- euro.worldclim[[c(1,8,12,17)]]
if(requireNamespace("hypervolume", quietly = TRUE)) {
    hypervolume.overlap(mont, cyr, env = env)
}

GBIF data for a clade of Iberolacerta lizards from spain

Description

This is some sample data downloaded from GBIF for the purposes of demonstrating ENMTools functionality.

Usage

iberolacerta.clade

Format

An enmtools.clade object with seven species and a phylogeny.


identity.test Conduct a niche identity/equivalency test as described in Warren et al. 2008.

Description

identity.test Conduct a niche identity/equivalency test as described in Warren et al. 2008.

Usage

identity.test(
  species.1,
  species.2,
  env,
  type,
  f = NULL,
  nreps = 99,
  nback = 1000,
  bg.source = "default",
  low.memory = FALSE,
  rep.dir = NA,
  verbose = FALSE,
  clamp = TRUE,
  ...
)

Arguments

species.1

An emtools.species object

species.2

An enmtools.species object

env

A SpatRaster object containing environmental data

type

The type of model to construct, currently accepts "glm", "mx", "bc", "gam", "rf", or "dm"

f

A function to use for model fitting. Only required for GLM models at the moment.

nreps

Number of replicates to perform

nback

Number of background points for models

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

low.memory

When set to TRUE, replicate models are written to disc instead of being stored in the output object. Replicate models stored in the output object contain paths to the replicate models on disk instead of the rasters themselves.

rep.dir

Directory for storing replicate models when low.memory is set to TRUE. If not specified, the working directory will be used.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

Controls whether empirical and replicate models should be clamped to the environment space used for training.

...

Additional arguments to be passed to model fitting functions.

Value

results A list containing the replicates, models for the empirical data, and summary statistics and plots.

Examples

cyreni <- iberolacerta.clade$species$cyreni
monticola <- iberolacerta.clade$species$monticola
cyreni$range <- background.raster.buffer(cyreni$presence.points, 100000, euro.worldclim)
monticola$range <- background.raster.buffer(monticola$presence.points, 100000, euro.worldclim)
identity.test(cyreni, monticola, env = euro.worldclim, type = "glm",
f = pres ~ bio1 + bio12, nreps = 10)

install.extras

Description

Convenience function that installs all extra packages used in ENMTools. ENMTools uses functions from a lot of external packages, and due to CRAN best practices it doesn't install those packages by default. The function install.extras() calls install.packages with a list of all of the extra packages that are not already available. Use [check.extras()] to find out which packages are needed for a list of functions.

Usage

install.extras(funs = NULL, install = TRUE, ...)

Arguments

funs

character vector of ENMTools function names to install extra dependencies for. If 'NULL', extras for all ENMTools functions will be installed.

install

Should the packages be installed?

...

Other parameters to be passed to install.packages

Value

The list of missing packages is return invisibly.

Examples

install.extras(install = FALSE)

Generic function for making interactive plots of ENMTools models and species

Description

Function that takes an enmtools.model or enmtools.species object and calls the class-appropriate interactive.plot.xx function for it. These functions use leaflet for mapping and will only function properly if you have an active internet connection.

Usage

interactive.plot(x, ...)

Arguments

x

entools.model or species object to plot

...

other arguments passed to interactive.plot.enmtools.model or interactive.plot.enmtools.species

Value

An interactive leaflet plot depicting the predictions and data from the enmtools.model object.


Plot an enmtools.model object on an interactive map

Description

Function that take an enmtools.model object and plots an interactive map of the presence points, background points (if applicable), and species suitability map. This function uses leaflet for mapping and will only function properly if you have an active internet connection.

Usage

## S3 method for class 'enmtools.model'
interactive.plot(
  x,
  map.provider = "Esri.WorldPhysical",
  cluster.points = FALSE,
  raster.opacity = 1,
  max.bytes = 4194304,
  ...
)

Arguments

x

entools.model object to plot

map.provider

Name of a map provider for the underlying interactive base map. Default is "Esri.WorldPhysical", and attractive topographic map with no place labels. A preview of all map provider options can be viewed at http://leaflet-extras.github.io/leaflet-providers/preview/

cluster.points

Should points be clustered? If TRUE, points close together will be grouped into clusters that can be interactively expanded by clicking on them.

raster.opacity

Specifies the opacity level of the suitability raster.

max.bytes

Maximum size of raster image to plot. Defaults to 4MB (4194304 bytes) but can be overridden if you have a large raster. Be aware that the image will be knitted into an output file if you're working in R Markdown, causing your output file to be huge if the raster is huge.

...

other arguments (not used currently)

Value

An interactive leaflet plot depicting the predictions and data from the enmtools.model object.


Plot an enmtools.species object on an interactive map

Description

Function that take an enmtools.species object and plots an interactive map of the presence points, background points (if applicable), and species range raster (if applicable). This function uses leaflet for mapping and will only function properly if you have an active internet connection.

Usage

## S3 method for class 'enmtools.species'
interactive.plot(
  x,
  map.provider = "Esri.WorldPhysical",
  cluster.points = FALSE,
  max.bytes = 4194304,
  ...
)

Arguments

x

entools.species object to plot

map.provider

Name of a map provider for the underlying interactive base map. Default is "Esri.WorldPhysical", and attractive topographic map with no place labels. A preview of all map provider options can be viewed at http://leaflet-extras.github.io/leaflet-providers/preview/

cluster.points

Should points be clustered? If TRUE, points close together will be grouped into clusters that can be interactively expanded by clicking on them.

max.bytes

Maximum size of range raster image to plot. Defaults to 4MB (4194304 bytes) but can be overridden if you have a large range raster. Be aware that the image will be knitted into an output file if you're working in R Markdown, causing your output file to be huge if the raster is huge.

...

other arguments (not used currently)

Value

An interactive leaflet plot visualizing the data present in the species object.


marginal.plots Plots the marginal response of a model to an environmental variable with all other variables held at their mean in env

Description

marginal.plots Plots the marginal response of a model to an environmental variable with all other variables held at their mean in env

Usage

marginal.plots(model, env, layer, standardize = TRUE, verbose = FALSE)

Arguments

model

An enmtools model object

env

A SpatRaster object containing environmental data

layer

The name of the layer to plot

standardize

Whether to set the maximum of the response function to 1, or to instead use the raw values.

verbose

Controls printing of messages

Value

results A plot of the marginal response of the model to the environmental variable.

Examples

cyreni.glm <- enmtools.glm(iberolacerta.clade$species$cyreni,
f = pres ~ bio1 + bio12, euro.worldclim)
marginal.plots(cyreni.glm, euro.worldclim, "bio1")

Takes a list of enmtools.species objects and uses model selection to ask whether they're better treated jointly or separately

Description

Takes a list of enmtools.species objects and uses model selection to ask whether they're better treated jointly or separately

Usage

moses.list(
  species.list,
  env,
  f = NULL,
  eval = FALSE,
  nback = 1000,
  bg.source = "default",
  verbose = FALSE,
  step = FALSE,
  ...
)

Arguments

species.list

A list of enmtools.species objects, or an enmtools.clade object.

env

A SpatRaster of environmental data.

f

A GLM-style function for model fitting

eval

Boolean indicating whether or not GLMs should be evaluated using AUC/TSS/etc.

nback

Number of background points to generate, if any

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

step

Logical determining whether to do stepwise model selection or not

...

further arguments to be passed to enmtools.glm

Value

A list containing GLMs for the groups separately and together, as well as AIC values for those models.


multistack.pca, simultaneous PCA on more than one stack of environmental rasters

Description

multistack.pca, simultaneous PCA on more than one stack of environmental rasters

Usage

multistack.pca(..., n = 2)

Arguments

...

Any number of environmental raster stacks or bricks

n

The number of PCA layers to return

Value

A list containing a stack or brick of rasters for each input set representing the top n pca axes of the initial environmental variables, as well as the pca object from the analysis that produced them and some useful plots showing the distribution of each PC in the different stacks.

Examples

test1 <- terra::crop(euro.worldclim, terra::ext(-10, -5, 40, 43))
test2 <- terra::crop(euro.worldclim, terra::ext(-5, 5, 40, 48))
test3 <- terra::crop(euro.worldclim, terra::ext(5, 15, 44, 48))
multistack.pca(test1, test2, test3)

Takes an overlap matrix and a tree and returns average overlap at nodes using Fitzpatrick & Turelli averaging method. Typicall called via enmtools.aoc rather than used directly.

Description

Takes an overlap matrix and a tree and returns average overlap at nodes using Fitzpatrick & Turelli averaging method. Typicall called via enmtools.aoc rather than used directly.

Usage

node.overlap(overlap, tree)

Arguments

overlap

An overlap matrix

tree

A tree

Value

A data frame of node ages and overlaps


Takes two emtools.species objects with range rasters, calculates overlap between them as in Cardillo and Warren 2016

Description

Takes two emtools.species objects with range rasters, calculates overlap between them as in Cardillo and Warren 2016

Usage

point.overlap(x, y)

Arguments

x

An enmtools.species object containing presence points

y

An enmtools.species object containing presence points

Value

A numeric value measuring the overlap between point distributions.

Examples

cyreni <- iberolacerta.clade$species$cyreni
monticola <- iberolacerta.clade$species$monticola
point.overlap(cyreni, monticola)

rangebreak.blob Conduct a blob rangebreak test as described in Glor and Warren 2011.

Description

rangebreak.blob Conduct a blob rangebreak test as described in Glor and Warren 2011.

Usage

rangebreak.blob(
  species.1,
  species.2,
  env,
  type,
  f = NULL,
  nreps = 99,
  nback = 1000,
  bg.source = "default",
  low.memory = FALSE,
  rep.dir = NA,
  verbose = FALSE,
  clamp = TRUE,
  ...
)

Arguments

species.1

An emtools.species object

species.2

An enmtools.species object

env

A SpatRaster object containing environmental data

type

The type of model to construct, currently accepts "glm", "mx", "bc", "gam", or "dm"

f

A function to use for model fitting. Only required for GLM models at the moment.

nreps

Number of replicates to perform

nback

Number of background points for models

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

low.memory

When set to TRUE, replicate models are written to disc instead of being stored in the output object. Replicate models stored in the output object contain paths to the replicate models on disk instead of the rasters themselves.

rep.dir

Directory for storing replicate models when low.memory is set to TRUE. If not specified, the working directory will be used.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

Controls whether empirical and replicate models should be clamped to the environment space used for training.

...

Additional arguments to be passed to model fitting functions.

Value

results A list containing the replicates, models for the empirical data, and summary statistics and plots.

Examples

cyreni <- iberolacerta.clade$species$cyreni
aranica <- iberolacerta.clade$species$aranica

rangebreak.linear Conduct a linear rangebreak test as described in Glor and Warren 2011.

Description

rangebreak.linear Conduct a linear rangebreak test as described in Glor and Warren 2011.

Usage

rangebreak.linear(
  species.1,
  species.2,
  env,
  type,
  f = NULL,
  nreps = 99,
  nback = 1000,
  bg.source = "default",
  low.memory = FALSE,
  rep.dir = NA,
  verbose = FALSE,
  clamp = TRUE,
  ...
)

Arguments

species.1

An emtools.species object

species.2

An enmtools.species object

env

A SpatRaster object containing environmental data

type

The type of model to construct, currently accepts "glm", "mx", "bc", "gam", or "dm"

f

A function to use for model fitting. Only required for GLM models at the moment.

nreps

Number of replicates to perform

nback

Number of background points for models

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

low.memory

When set to TRUE, replicate models are written to disc instead of being stored in the output object. Replicate models stored in the output object contain paths to the replicate models on disk instead of the rasters themselves.

rep.dir

Directory for storing replicate models when low.memory is set to TRUE. If not specified, the working directory will be used.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

Controls whether empirical and replicate models should be clamped to the environment space used for training.

...

Additional arguments to be passed to model fitting functions.

Value

results A list containing the replicates, models for the empirical data, and summary statistics and plots.

Examples

cyreni <- iberolacerta.clade$species$cyreni
aranica <- iberolacerta.clade$species$aranica
rangebreak.linear(cyreni, aranica, env = euro.worldclim, type = "glm",
f= pres ~ bio1 + bio12, nreps = 10)

rangebreak.ribbon Conduct a ribbon rangebreak test as described in Glor and Warren 2011.

Description

rangebreak.ribbon Conduct a ribbon rangebreak test as described in Glor and Warren 2011.

Usage

rangebreak.ribbon(
  species.1,
  species.2,
  ribbon,
  env,
  type,
  f = NULL,
  width = 1,
  nreps = 99,
  nback = 1000,
  bg.source = "default",
  low.memory = FALSE,
  rep.dir = NA,
  verbose = FALSE,
  clamp = TRUE,
  ...
)

Arguments

species.1

An emtools.species object

species.2

An enmtools.species object

ribbon

An enmtools.species object representing the region of marginal habtiat in the overlap between the species' ranges

env

A SpatRaster object containing environmental data

type

The type of model to construct, currently accepts "glm", "mx", "bc", or "dm"

f

A function to use for model fitting. Only required for GLM models at the moment.

width

Width of the ribbon, in the same units as the occurrence points (e.g, decimal degrees)

nreps

Number of replicates to perform

nback

Number of background points for models

bg.source

Source for drawing background points. If "points", it just uses the background points that are already in the species object. If "range", it uses the range raster. If "env", it draws points at randome from the entire study area outlined by the first environmental layer.

low.memory

When set to TRUE, replicate models are written to disc instead of being stored in the output object. Replicate models stored in the output object contain paths to the replicate models on disk instead of the rasters themselves.

rep.dir

Directory for storing replicate models when low.memory is set to TRUE. If not specified, the working directory will be used.

verbose

Controls printing of various messages progress reports. Defaults to FALSE.

clamp

Controls whether empirical and replicate models should be clamped to the environment space used for training.

...

Additional arguments to be passed to model fitting functions.

Value

results A list containing models for the replicates, models for the empirical data, and summary statistics and plots.

Examples

cyreni <- iberolacerta.clade$species$cyreni
aranica <- iberolacerta.clade$species$aranica

# We're just going to fudge together occurrence data from a ribbon here
# from random points between the two species' ranges
p <- data.frame(x = runif(50, -4, -2), y = runif(50, 40, 43))
p <- terra::vect(p, geom = c("x", "y"), crs = terra::crs(cyreni$presence.points))
bg <- background.buffer(p, 100000, mask = euro.worldclim[[1]], n = 100, return.type = "points")
ribbon <- enmtools.species(species.name = "ribbon", presence.points = p, background.points = bg)

rangebreak.ribbon(cyreni, aranica, ribbon = ribbon, env = euro.worldclim,
type = "glm", f= pres ~ bio1 + bio12, nreps = 10)

raster.breadth, applies measures of niche breadth to an ENM

Description

This function measures the spatial heterogeneity of the distribution of suitability scores from an ENM. It returns Levins' (1968) two metrics of niche breadth.

Usage

raster.breadth(x, verbose = FALSE)

Arguments

x

An object of class raster or RasterLayer, or an ENMTools model object containing a suitability raster.

verbose

Controls printing of diagnostic messages

Details

Levins, R. 1968. Evolution in changing environments: some theoretical explorations. Princeton University Press.

Value

results A vector containing the two metrics B1 and B2 for niche breadth.

Examples

aurelioi.glm <- enmtools.glm(iberolacerta.clade$species$aurelioi, euro.worldclim,
f = pres ~ bio1 + bio12)
raster.breadth(aurelioi.glm)

Calculates the correlation coefficient between two rasters.

Description

Calculates the correlation coefficient between two rasters.

Usage

raster.cor(x, y, method = "spearman")

Arguments

x

Either a raster or an ENMTools model object with a suitability raster.

y

Either a raster or an ENMTools model object with a suitability raster.

method

The method to be used for calculating correlations. Defaults to spearman, but can take "kendall" or "pearson" as well.

Value

A numeric correlation coefficient.

Examples

data(euro.worldclim)
raster.cor(euro.worldclim[[1]], euro.worldclim[[2]])

Takes a raster stack and returns a data frame containing Pearson correlation coefficients between the included rasters

Description

Takes a raster stack and returns a data frame containing Pearson correlation coefficients between the included rasters

Usage

raster.cor.matrix(env, method = "pearson")

Arguments

env

A SpatRaster object containing two or more rasters

method

Type of correlation to measure. Can do "pearson", "kendall", or "spearman"

Value

A data frame of correlation coefficients for a set of rasters.

Examples

data(euro.worldclim)
raster.cor.matrix(euro.worldclim)

Takes a raster stack and returns a data frame containing Pearson correlation coefficients between the included rasters

Description

Takes a raster stack and returns a data frame containing Pearson correlation coefficients between the included rasters

Usage

raster.cor.plot(env, method = "pearson")

Arguments

env

A SpatRaster object containing two or more rasters

method

Type of correlation to measure. Can do "pearson", "kendall", or "spearman"

Value

A list of two plots. The first maps the correlations between rasters into an MDS space, so that predictors that fall close together in that space are more correlated. The second plot is a heatmap depicting the correlations between pairs of layers.

Examples

data(euro.worldclim)
raster.cor.plot(euro.worldclim)

raster.overlap, measures overlap between two ENMs

Description

This function measures similarity in the geographic distribution of suitability scores from two ENMs. It returns two metrics, I and D. These metrics are described in Warren et al. 2008.

Usage

raster.overlap(x, y, verbose = FALSE)

Arguments

x

A raster or RasterLayer object, or ENMTools model object containing a suitability raster.

y

Another raster or RasterLayer object, or ENMTools model object containing a suitability raster.

verbose

Controls printing of diagnostic messages

Value

results A vector containing the three metrics (I, D, and Spearman rank correlation)

Examples

aurelioi.glm <- enmtools.glm(iberolacerta.clade$species$aurelioi,
euro.worldclim, f = pres ~ bio1 + bio12)
aranica.glm <- enmtools.glm(iberolacerta.clade$species$aranica,
euro.worldclim, f = pres ~ bio1 + bio12)
raster.overlap(aurelioi.glm, aranica.glm)

raster.pca, PCA on a set of environmental rasters

Description

raster.pca, PCA on a set of environmental rasters

Usage

raster.pca(env, n)

Arguments

env

A set of environmental layers

n

The number of PCA layers to return

Value

A list containing a stack of rasters representing the top n pca axes of the initial environmental variables, as well as the pca object from the analysis that produced them.

Examples

env.pca <- raster.pca(euro.worldclim, 2)

raster.resid Measure standardized residuals from a linear regression between two rasters.

Description

This function builds a linear model for the relationship between two rasters, and returns the linear model and a spatial raster of the residuals from that model.

Usage

raster.resid(x, y)

Arguments

x

A raster or RasterLayer object, or ENMTools model object containing a suitability raster.

y

Another raster or RasterLayer object, or ENMTools model object containing a suitability raster.

Value

results A list containing a raster of residuals from a linear regression between the two supplied rasters and the linear model itself.

Examples

data(euro.worldclim)
raster.resid(euro.worldclim[[1]], euro.worldclim[[2]])

raster.standardize, standardizes all values in a raster file

Description

This function is used by a lot of the metrics calculated by ENMTools, in order to standardize suitability scores so they sum to 1 over a geographic space.

Usage

raster.standardize(x, verbose = FALSE)

Arguments

x

A raster or RasterLayer object, or an ENMTools model object containing a suitability raster.

verbose

Controls printing of diagnostic messages

Value

A new raster object, standardized so that values sum to 1

Examples

raster.standardize(euro.worldclim[[1]])

get terra to produce same output as raster::rasterToPoints

Description

get terra to produce same output as raster::rasterToPoints

Usage

rasterToPoints2(rast)

Arguments

rast

A raster to convert to points


Simulate a point process from an enmtools.model object

Description

Function that takes an enmtools.model object and simulates points from it using a point process.

Usage

sim.points(
  object,
  n.points = 1000,
  seed = NA,
  sample.type = "ppp",
  replace = FALSE,
  threshold = NA,
  ...
)

Arguments

object

entools.model object to simulate from

n.points

approximate number of points to simulate. You may get small number fewer or greater. If you need an exact number of points, generate too many, then drop the extra ones.

seed

optional seed for the random number generator

sample.type

method for sampling occurrence points. Default is "ppp", which is a poisson point process. Also accepts "binomial" for treating suitabilities as binomial trials, "thresh.pa" for sampling with equal probability every grid cell above a certain threshold value, and "thresh.con" for sampling in proportion to suitability above a certain threshold value.

replace

whether to sample with replacement.

threshold

a threshold suitability below which probability of sampling drops to zero. Used for "thresh.pa" and "thresh.con" sampling.

...

additional parameters, not currently used but included for S3 compatability

Value

A data frame of simulated points from the enmtools.model object


Takes a csv file and uses it to construct one or more enmtools.species objects. It constructs one object per unique value in the "species.col" column.

Description

Takes a csv file and uses it to construct one or more enmtools.species objects. It constructs one object per unique value in the "species.col" column.

Usage

species.from.file(filename, species.col = "species")

Arguments

filename

Name of a .csv file

species.col

Name of the column from the csv file to use for species names. Default is "species".

Value

A list containing species objects, one for each unique value in species.col.


threespace.plot, A plot that compares the environmental distribution of presence points, background points, and the set of supplied environmental layers.

Description

threespace.plot, A plot that compares the environmental distribution of presence points, background points, and the set of supplied environmental layers.

Usage

threespace.plot(model, env, maxpts = NA)

Arguments

model

An enmtools.model object

env

A set of environment layers

maxpts

Maximum number of points to plot from env layers

Value

A ggplot2 object that plots the distribution of environments in the climate layers to the distribution of environments at background and presence localities.

Examples

my.model<- enmtools.gam(iberolacerta.clade$species$monticola, euro.worldclim)
threespace.plot(my.model, euro.worldclim)

Takes a set of points and a raster mask and returns a data frame trimmed so that only one point is returned per grid cell in the mask raster.

Description

Takes a set of points and a raster mask and returns a data frame trimmed so that only one point is returned per grid cell in the mask raster.

Usage

trimdupes.by.raster(points, mask)

Arguments

points

A two column data frame with X and Y coordinates

mask

A raster to use as a mask for drawing points

Value

A new data frame with one point per grid cell.

Examples

pts <- iberolacerta.clade$species$monticola$presence.points
trimdupes.by.raster(pts, euro.worldclim)

export

Description

export

Usage

unwrap_list(l)

Arguments

l

A list containing species objects that need to be converted


visualize.enm, Makes a heatmap of suitability of habitat in environment space according to a given model

Description

visualize.enm, Makes a heatmap of suitability of habitat in environment space according to a given model

Usage

visualize.enm(
  model,
  env,
  nbins = 100,
  layers = colnames(model$analysis.df)[1:2],
  plot.test.data = FALSE,
  plot.points = TRUE,
  minmax = "env"
)

Arguments

model

An enmtools.model object

env

A set of environmental layers

nbins

The number of bins per layer to use for drawing environment space

layers

A vector of layer names to use for drawing environment space

plot.test.data

Logical determining whether test data should be plotted, if present. If test data is plotted, it will appear as translucent green triangles.

plot.points

Logical determining whether presence points should be plotted on suitability plot

minmax

Either "env", to set the minima and maxima using the environment layers, "points" to set the minima and maxima using the presence and background data, or a named list of minima and maxima for each layer.

Value

suit.plot A list containing two dimensional plot of an ENM in environment space and a plot of the available environments.

Examples

aurelioi.glm <- enmtools.glm(iberolacerta.clade$species$aurelioi, euro.worldclim,
f = pres ~ poly(bio1, 4) + poly(bio12, 4))
visualize.enm(aurelioi.glm, euro.worldclim, layers = c("bio1", "bio12"))

visualize.overlap, Makes a contour map of suitability of habitat in environment space for two models

Description

visualize.overlap, Makes a contour map of suitability of habitat in environment space for two models

Usage

visualize.overlap(
  model.1,
  model.2,
  env,
  nbins = 100,
  layers,
  plot.points = TRUE
)

Arguments

model.1

An enmtools.model object

model.2

An enmtools.model object

env

A set of environmental layers

nbins

The number of bins per layer to use for drawing environment space

layers

A vector of layer names to use for drawing environment space

plot.points

Logical determining whether presence points should be plotted on suitability plot

Value

overlap.plot A two dimensional plot of an ENM

Examples

ar <- iberolacerta.clade$species$aranica
au <- iberolacerta.clade$species$aurelioi
aranica.dm <- enmtools.dm(ar, euro.worldclim)
aurelioi.dm <- enmtools.dm(au, euro.worldclim)
visualize.overlap(aranica.dm, aurelioi.dm, euro.worldclim, layers = c("bio1", "bio9"))

export

Description

export

Usage

wrap_list(l)

Arguments

l

A list containing species objects that need to be converted