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.
splmRF(formula, data, ...)
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.
A data frame or sf
object object that contains
the variables in fixed
, random
, and partition_factor
as well as geographical information. If an sf
object is
provided with POINT
geometries, the x-coordinates and y-coordinates
are used directly. If an sf
object is
provided with POLYGON
geometries, the x-coordinates and y-coordinates
are taken as the centroids of each polygon.
Additional named arguments to ranger::ranger()
or splm()
.
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.
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.
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.
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.
# \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 7
#> -3.5725319 26.4587445 19.5974234 21.1952229 8.9775683 37.5782280 -1.4436623
#> 8 9 10 11 12 13 14
#> 19.2131864 11.1342578 13.2823742 5.7900802 13.8752714 -3.6477720 17.9235482
#> 15 16 17 18 19 20 21
#> 24.0233068 18.0928379 16.3788158 9.2385326 -5.1475530 17.7799398 -2.7429046
#> 22 23 24 25 26 27 28
#> 1.3107340 2.1589235 8.5745735 10.9500498 -1.4172030 23.9596667 9.2075272
#> 29 30 31 32 33 34 35
#> 27.2234525 20.3656125 2.6071351 14.5805166 9.2895198 -1.8987871 1.1078926
#> 36 37 38 39 40 41 42
#> 7.6010931 21.5443763 19.4887466 4.6097204 9.1272702 14.1613482 30.2187344
#> 43 44 45 46 47 48 49
#> 15.4103782 29.8740443 -1.5470827 9.4929825 15.0473029 21.1039899 15.5068372
#> 50 51 52 53 54 55 56
#> 2.8236578 22.6090264 17.5696220 6.6264887 -0.5927998 4.2727309 15.1086000
#> 57 58 59 60 61 62 63
#> 13.8935915 5.1378957 16.8174694 12.4314919 25.3900183 35.6908376 2.8196305
#> 64 65 66 67 68 69 70
#> 8.7205120 23.6863688 3.2612406 0.4832931 12.5655364 2.0626310 9.9759512
#> 71 72 73 74 75 76 77
#> -5.6374304 16.6760385 3.9966741 8.1074041 -5.2948606 -5.7236063 20.3775865
#> 78 79 80 81 82 83 84
#> 1.8029981 11.7215686 15.3946723 25.7678172 -3.5004424 24.0011169 -1.0889296
#> 85 86 87 88 89 90 91
#> 0.4270438 7.5487744 -1.0934757 4.2643062 -1.4467171 25.6115937 17.6130139
#> 92 93 94 95 96 97 98
#> 5.9973527 12.2175818 30.8195400 23.8290769 21.9516414 14.9360010 21.4966266
#> 99 100
#> 8.8171750 13.8538787
# }