Fit random forest spatial residual models for point-referenced data (i.e., geostatistical models) using random forest to fit the mean and a spatial linear model to fit the residuals. The spatial linear model fit to the residuals can incorporate variety of estimation methods, allowing for random effects, anisotropy, partition factors, and big data methods.
Arguments
- formula
A two-sided linear formula describing the fixed effect structure of the model, with the response to the left of the
~
operator and the terms on the right, separated by+
operators.- data
A data frame or
sf
object object that contains the variables infixed
,random
, andpartition_factor
as well as geographical information. If ansf
object is provided withPOINT
geometries, the x-coordinates and y-coordinates are used directly. If ansf
object is provided withPOLYGON
geometries, the x-coordinates and y-coordinates are taken as the centroids of each polygon.- ...
Additional named arguments to
ranger::ranger()
orsplm()
.
Value
A list with several elements to be used with predict()
. These
elements include the function call (named call
), the random forest object
fit to the mean (named ranger
),
the spatial linear model object fit to the residuals
(named splm
or splm_list
), and an object can contain data for
locations at which to predict (called newdata
). The newdata
object contains the set of
observations in data
whose response variable is NA
.
If spcov_type
or spcov_initial
(which are passed to splm()
)
are length one, the list has class splmRF
and the spatial linear
model object fit to the residuals is called splm
, which has
class splm
. If
spcov_type
or spcov_initial
are length greater than one, the
list has class splmRF_list
and the spatial linear model object
fit to the residuals is called splm_list
, which has class splm_list
.
and contains several objects, each with class splm
.
An splmRF
object to be used with predict()
. There are
three elements: ranger
, the output from fitting the mean model with
ranger::ranger()
; splm
, the output from fitting the spatial
linear model to the ranger residuals; and newdata
, the newdata
object, if relevant.
Details
The random forest residual spatial linear model is described by
Fox et al. (2020). A random forest model is fit to the mean portion of the
model specified by formula
using ranger::ranger()
. Residuals
are computed and used as the response variable in an intercept-only spatial
linear model fit using splm()
. This model object is intended for use with
predict()
to perform prediction, also called random forest
regression Kriging.
Note
This function does not perform any internal scaling. If optimization is not stable due to large extremely large variances, scale relevant variables so they have variance 1 before optimization.
References
Fox, E.W., Ver Hoef, J. M., & Olsen, A. R. (2020). Comparing spatial regression to random forests for large environmental data sets. PloS one, 15(3), e0229509.
Examples
# \donttest{
sulfate$var <- rnorm(NROW(sulfate)) # add noise variable
sulfate_preds$var <- rnorm(NROW(sulfate_preds)) # add noise variable
sprfmod <- splmRF(sulfate ~ var, data = sulfate, spcov_type = "exponential")
predict(sprfmod, sulfate_preds)
#> 1 2 3 4 5 6
#> 4.14811155 34.20366825 7.33453772 17.96184350 -3.20490296 20.96357210
#> 7 8 9 10 11 12
#> 9.77333126 21.59431036 0.28085046 19.32424259 5.44592523 24.02731993
#> 13 14 15 16 17 18
#> -2.60319702 12.99030552 21.81919201 12.42642421 15.81365970 10.23612701
#> 19 20 21 22 23 24
#> 4.82310554 19.47580449 19.44629206 -0.67681325 12.71849847 7.89390537
#> 25 26 27 28 29 30
#> 0.31965151 -6.06491078 16.96911644 5.23163711 26.14082233 6.72592416
#> 31 32 33 34 35 36
#> -7.97086704 -1.46909096 8.41488984 -5.95366612 -0.16525209 11.86042576
#> 37 38 39 40 41 42
#> 28.29883688 4.55385400 14.78311298 14.65466761 8.89136914 22.09187490
#> 43 44 45 46 47 48
#> 16.98782287 19.37465814 -1.22987449 10.88408872 9.69769160 15.57709856
#> 49 50 51 52 53 54
#> 15.90109210 -3.39214162 20.02784106 18.82558258 9.79976485 -2.18033791
#> 55 56 57 58 59 60
#> 4.58115158 16.03624652 12.38814855 3.91411523 15.28622635 8.25106583
#> 61 62 63 64 65 66
#> 26.33957296 27.14301775 -5.53676321 18.01290386 22.10296575 -5.41299038
#> 67 68 69 70 71 72
#> -6.91367097 0.91370651 -2.39102508 5.79030840 0.76894428 16.71802523
#> 73 74 75 76 77 78
#> 16.30935629 3.27766360 -2.28821455 -4.59497990 18.65988727 -4.33394655
#> 79 80 81 82 83 84
#> 23.08629834 18.08347153 19.71114413 0.01135263 2.54490969 -5.31786728
#> 85 86 87 88 89 90
#> -2.57431174 0.80961825 2.76179784 -1.58677621 -2.92853432 17.20972966
#> 91 92 93 94 95 96
#> 2.80647555 4.82133299 14.37001905 32.80365573 11.57957115 14.61975234
#> 97 98 99 100
#> 22.06148557 12.87569700 18.36816546 14.23775635
# }