Learn R Programming

itsdm

Overview

itsdm calls isolation forest and variations such as SCiForest and EIF to model species distribution. It provides features including:

  • A few functions to download environmental variables.
  • Outlier tree-based suspicious environmental outliers detection.
  • Isolation forest-based environmental suitability modeling.
  • Non-spatial response curves of environmental variables.
  • Spatial response maps of environmental variables.
  • Variable importance analysis.
  • Presence-only model evaluation.
  • Method to convert predicted suitability to presence-absence map.
  • Variable contribution analysis for the target observations.
  • Method to analyze the spatial impacts of changing environment.

Installation

Install the CRAN release of itsdm with

install.packages("itsdm")

You can install the development version of itsdm from GitHub with:

# install.packages("remotes")
remotes::install_github("LLeiSong/itsdm")

Example

This is a basic example which shows you how to solve a common problem:

library(itsdm)
library(dplyr)
library(stars)
library(ggplot2)

# Using a pseudo presence-only occurrence dataset of
# virtual species provided in this package
data("occ_virtual_species")
obs_df <- occ_virtual_species %>% filter(usage == "train")
eval_df <- occ_virtual_species %>% filter(usage == "eval")
x_col <- "x"
y_col <- "y"
obs_col <- "observation"
obs_type <- "presence_absence"

# Format the observations
obs_train_eval <- format_observation(
  obs_df = obs_df, eval_df = eval_df,
  x_col = x_col, y_col = y_col, obs_col = obs_col,
  obs_type = obs_type)

# Get environmental variables
env_vars <- system.file(
  'extdata/bioclim_tanzania_10min.tif',
  package = 'itsdm') %>% read_stars() %>%
  slice('band', c(1, 6, 12, 15))

# Train the model
mod <- isotree_po(
  obs_mode = "presence_absence",
  obs = obs_train_eval$obs,
  obs_ind_eval = obs_train_eval$eval,
  variables = env_vars, ntrees = 200,
  sample_size = 0.8, ndim = 2,
  seed = 123L)

# Check results
## Suitability
ggplot() +
  geom_stars(data = mod$prediction) +
  scale_fill_viridis_c('Predicted suitability',
                       na.value = 'transparent') +
  coord_equal() +
  theme_linedraw()

## Plot independent response curves
plot(mod$independent_responses, 
     target_var = c('bio1', 'bio12'))

The Shapley values-based analysis can apply to external models. Here is an example to analyze impacts of the bio12 decreasing 200 mm to species distribution based on Random Forest (RF) prediction:

# Prepare data
data("occ_virtual_species")
obs_df <- occ_virtual_species %>% 
  filter(usage == "train")

env_vars <- system.file(
  'extdata/bioclim_tanzania_10min.tif',
  package = 'itsdm') %>% read_stars() %>%
  slice('band', c(1, 5, 12)) %>% 
  split()

model_data <- stars::st_extract(
  env_vars, at = as.matrix(obs_df %>% select(x, y))) %>% 
  as.data.frame()
names(model_data) <- names(env_vars)
model_data <- model_data %>% 
  mutate(occ = obs_df[['observation']])
model_data$occ <- as.factor(model_data$occ)

mod_rf <- randomForest(
  occ ~ .,
  data = model_data,
  ntree = 200)

pfun <- function(X.model, newdata) {
  # for data.frame
  predict(X.model, newdata, type = "prob")[, "1"]
}

# Use a fixed value
climate_changes <- detect_envi_change(
  model = mod_rf,
  var_occ = model_data %>% select(-occ),
  variables = env_vars,
  target_var = "bio12",
  bins = 20,
  var_future = -200,
  pfun = pfun)

Contributor

  1. David Cortes, helps to improve the flexibility of calling isotree.

We are welcome any helps! Please make a pull request or reach out to lei.song@rutgers.edu if you want to make any contribution.

Funding

This package is part of project "Combining Spatially-explicit Simulation of Animal Movement and Earth Observation to Reconcile Agriculture and Wildlife Conservation". This project is funded by NASA FINESST program (award number: 80NSSC20K1640).

Reference

Song, L., & Estes, L. (2023). itsdm: Isolation forest-based presence-only species distribution modelling and explanation in r. Methods in Ecology and Evolution, 14(3), 831-840. https://doi.org/10.1111/2041-210X.14067

Song, L., Frazier, A. E., Estes, A. B., & Estes, L. D. (2025). A multi-scale approach for integrating species distribution models with landscape connectivity to identify critical linkage zones for African savanna elephants (Loxodonta africana). Ecological Modelling, 507, 111198. https://doi.org/10.1016/j.ecolmodel.2025.111198

Copy Link

Version

Install

install.packages('itsdm')

Monthly Downloads

198

Version

0.2.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Lei Song

Last Published

July 1st, 2025

Functions in itsdm (0.2.2)

plot.POEvaluation

Show model evaluation.
marginal_response

Calculate marginal responses of each variables.
itsdm-package

Isolation forest-based presence-only species distribution modeling
plot.IndependentResponse

Show independent response curves.
plot.EnviChange

Display the figure and map of the EnviChange object.
plot.EnvironmentalOutlier

Exhibit suspicious outliers in an observation dataset.
plot.MarginalResponse

Show marginal response curves.
mainland_africa

Boundary of mainland Africa
plot.ShapDependence

Show variable dependence plots and variable interaction plots obtained from Shapley values.
plot.SHAPSpatial

Display Shapley values-based spatial variable dependence maps.
occ_virtual_species

Occurrence dataset of a virtual species
plot.VariableContribution

Exhibit variable contribution for target observations.
plot.VariableAnalysis

Display variable importance.
plot.SpatialResponse

Display spatial variable dependence maps.
print.EnviChange

Print summary information from EnviChange object.
print.POEvaluation

Print summary information from model evaluation object (POEvaluation).
variable_contrib

Evaluate variable contributions for targeted observations.
print.PAConversion

Print summary information from PAConversion object.
variable_analysis

Function to evaluate relative importance of each variable.
spatial_response

Calculate spatial response or dependence figures.
suspicious_env_outliers

Function to detect suspicious outliers based on environmental variables.
shap_spatial_response

Calculate shapley values-based spatial response.
shap_dependence

Calculate Shapley value-based variable dependence.
print.VariableAnalysis

Print summary information from variable importance object (VariableAnalysis).
worldclim2

Download environmental variables made by worldclim version 2.1.
probability

Estimate suitability on stars object using trained isolation.forest model.
print.ReducedImageStack

Print summary information from ReducedImageStack object.
print.EnvironmentalOutlier

Print summary information from EnvironmentalOutlier object.
print.POIsotree

Print summary information from POIsotree object.
print.FormatOccurrence

Print summary information from FormatOccurrence object.
independent_response

Calculate independent responses of each variables.
detect_envi_change

Detect areas influenced by a changing environment variable.
evaluate_po

Evaluate the model based on presence-only data.
future_worldclim2

A function to parse the future climate from worldclim version 2.1.
future_cmcc_bioclim

Download future Bioclimatic indicators (BIOs) named CMCC-BioClimInd.
dim_reduce

Remove environmental variables that have high correlation with others.
format_observation

Format the occurrence dataset for usage in itsdm
isotree_po

Build Isolation forest species distribution model and explain the the model and outputs.
cmcc_bioclim

Download historic Bioclimatic indicators (BIOs) named CMCC-BioClimInd.
convert_to_pa

Convert predicted suitability to presence-absence map.
plot.PAConversion

Display results of conversion to presence-absence (PA).