How to include the effect of the spatial autocorrelation in random forest algorithm? I have spatial autocorrelation (SAC) in my observations and I want to use two species distribution models Random forests and logistic regression, I’m planning to include the SAC as an autocovariate «  autocov» estimated through the auto-logistic regression (Augustin et al 1996). Now how to include the SAC in the random forests? Can I reuse the same variable « autocov », estimated in the auto-logistic model, as a new covariate in RF?
 A: Almost yes. We can use it as a new covariate.
Spatial correlation between measurements means that across the continuum defined by positional information (say, longitude and latitude) there is some information exchange. Therefore it is natural to simply include lon-lat measurements in our covariates. Given that a random forest (RF) (and any tree-based learner) can naturally include interactions between underlying variables these will automatically be included. This is the simplest we can do and requires almost no additional work. As always we can acquire prediction intervals for our RF by using quantile regression forests (QRF).
That said, we can do a step forward and combine random forest (a "standard regression" technique) with kriging (KR) (a technique particularly suited for spatially autocorrelated measurements). For example Hengl et al. (2015) Mapping Soil Properties of Africa at 250 m Resolution: Random Forests Significantly Improve Current Predictions specifically present that; Fox et al. (2020) Comparing spatial regression to random forests for large environmental data sets give a more comprehensive view on the matter doing a more structure performance assessment showing that RF+KR holds a slight advantage of a spatial linear model (SLM). Hengl has an extensive tutorial on using RF+KR on this GitHub here; it combines the RF library ranger with the buffer distances to all points as covariates using the spatial data analysis library raster. One of the examples is particularly for the spatial prediction of a categorical variable so it compares well to the concept of a logistic model.
A small caveat: These RF-based techniques are much more computationally intensive than usual model-based geostatistics, they also make fewer assumptions and they are understandably much more data-hungry. (That is true for all RF-approaches when compare to a simple GLM - eg. van der Ploeg et al. (2014) Modern modelling techniques are data hungry: a simulation study for predicting dichotomous endpoints for more details). I would strongly urge you to do a small simulation study based on your sample size to ensure you get reasonable convergence.
