Learn R Programming

spatialRF (version 1.1.5)

Easy Spatial Modeling with Random Forest

Description

Automatic generation and selection of spatial predictors for Random Forest models fitted to spatially structured data. Spatial predictors are constructed from a distance matrix among training samples using Moran's Eigenvector Maps (MEMs; Dray, Legendre, and Peres-Neto 2006 ) or the RFsp approach (Hengl et al. ). These predictors are used alongside user-supplied explanatory variables in Random Forest models. The package provides functions for model fitting, multicollinearity reduction, interaction identification, hyperparameter tuning, evaluation via spatial cross-validation, and result visualization using partial dependence and interaction plots. Model fitting relies on the 'ranger' package (Wright and Ziegler 2017 ).

Copy Link

Version

Install

install.packages('spatialRF')

Monthly Downloads

439

Version

1.1.5

License

MIT + file LICENSE

Maintainer

Blas M. Benito

Last Published

December 19th, 2025

Functions in spatialRF (1.1.5)

pca_multithreshold

Compute Principal Component Analysis at multiple distance thresholds
is_binary

Check if variable is binary with values 0 and 1
pca

Compute Principal Component Analysis
plants_response

Response variable name for plant richness examples
moran_multithreshold

Moran's I test across multiple distance thresholds
optimization_function

Compute optimization scores for spatial predictor selection
objects_size

Display sizes of objects in current R environment
residuals_test

Normality test of a numeric vector
plants_rf

Example fitted random forest model
plants_xy

Coordinates for plant richness data
plants_rf_spatial

Example fitted spatial random forest model
plot_evaluation

Visualize spatial cross-validation results
plot_importance

Visualize variable importance scores
plot_residuals_diagnostics

Plot residuals diagnostics
plot_moran

Plots a Moran's I test of model residuals
make_spatial_fold

Create spatially independent training and testing folds
get_predictions

Extract fitted predictions from model
mem_multithreshold

Compute Moran's Eigenvector Maps across multiple distance thresholds
plot_training_df_moran

Moran's I plots of a training data frame
get_residuals

Extract model residuals
plot_optimization

Optimization plot of a selection of spatial predictors
plot_response_curves

Plots the response curves of a model.
plot_tuning

Plots a tuning object produced by rf_tuning()
print_performance

print_performance
print_moran

Prints results of a Moran's I test
residuals_diagnostics

Normality test of a numeric vector
rf

Random forest models with Moran's I test of the residuals
make_spatial_folds

Create multiple spatially independent training and testing folds
mem

Compute Moran's Eigenvector Maps from distance matrix
%>%

Pipe operator
prepare_importance_spatial

Prepares variable importance objects for spatial models
rf_evaluate

Evaluates random forest models with spatial cross-validation
plants_df

Plant richness and predictors for American ecoregions
rf_compare

Compares models via spatial cross-validation
rf_spatial

Fits spatial random forest models
moran

Moran's I test for spatial autocorrelation
plot_response_surface

Plots the response surfaces of a random forest model
plants_distance

Distance matrix between ecoregion edges
rank_spatial_predictors

Ranks spatial predictors
plot_training_df

Scatterplots of a training data frame
rescale_vector

Rescales a numeric vector into a new range
rf_importance

Contribution of each predictor to model transferability
plants_predictors

Predictor variable names for plant richness examples
statistical_mode

Statistical mode of a vector
standard_error

Standard error of the mean of a numeric vector
print.rf

Custom print method for random forest models
print_evaluation

Prints cross-validation results
rf_repeat

Fits several random forest models on the same data
select_spatial_predictors_sequential

Sequential introduction of spatial predictors into a model
weights_from_distance_matrix

Transforms a distance matrix into a matrix of weights
thinning_til_n

Applies thinning to pairs of coordinates until reaching a given n
rf_tuning

Tuning of random forest hyperparameters via spatial cross-validation
setup_parallel_execution

Setup parallel execution with automatic backend detection
select_spatial_predictors_recursive

Finds optimal combinations of spatial predictors
print_importance

Prints variable importance
root_mean_squared_error

RMSE and normalized RMSE
thinning

Applies thinning to pairs of coordinates
the_feature_engineer

Suggest variable interactions and composite features for random forest models
filter_spatial_predictors

Remove redundant spatial predictors
get_evaluation

Extract evaluation metrics from cross-validated model
auc

Area under the ROC curve
auto_cor

Multicollinearity reduction via Pearson correlation
auto_vif

Multicollinearity reduction via Variance Inflation Factor
beowulf_cluster

Create a Beowulf cluster for parallel computing
get_moran

Extract Moran's I test results for model residuals
get_performance

Extract out-of-bag performance metrics from model
case_weights

Generate case weights for imbalanced binary data
get_response_curves

Extract response curve data for plotting
get_spatial_predictors

Extract spatial predictors from spatial model
default_distance_thresholds

Default distance thresholds for spatial predictors
.vif_to_df

Convert VIF values to data frame
double_center_distance_matrix

Double-center a distance matrix
get_importance

Extract variable importance from model
get_importance_local

Extract local variable importance from model