Skip to contents

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.

Usage

splmRF(formula, data, ...)

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 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().

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          7 
#>  1.4650638 25.3519736  3.6839758 29.7133547 15.7854201 22.1871708  1.6127427 
#>          8          9         10         11         12         13         14 
#>  8.8828673 -3.7270311 18.3580121  3.3058049 10.3879871 -0.9914569 14.0100008 
#>         15         16         17         18         19         20         21 
#> 20.7401759  9.3088395 27.2393221  5.5353741  6.4773599 23.5512849  2.0327482 
#>         22         23         24         25         26         27         28 
#>  1.9900377 -3.2520790 -3.7620590 16.5671835  0.6554495 20.1421875 10.9661974 
#>         29         30         31         32         33         34         35 
#> 15.0110640 16.5761131 -2.7837165  5.4683251 20.4581482  2.0987345  2.1711594 
#>         36         37         38         39         40         41         42 
#>  5.6182391 20.7866831 23.1085355 11.0701393 14.5749094  8.6141445 19.8942256 
#>         43         44         45         46         47         48         49 
#> 25.1971387 17.9105561 13.4829172  2.0772709 -4.0392365  9.6193731 24.2468941 
#>         50         51         52         53         54         55         56 
#> -2.8074280 18.2263987 10.8424667 -2.3738772 -5.9054008  2.9763653  9.6473487 
#>         57         58         59         60         61         62         63 
#> 11.4692320  6.2363249 17.3395828 21.3904762 21.9400397 15.3616913 -3.5265082 
#>         64         65         66         67         68         69         70 
#>  8.7314116 28.6232219 -7.6477062 -1.2273404  8.7757875  0.5168636  4.3078085 
#>         71         72         73         74         75         76         77 
#>  2.8300501 27.8123529  2.9357663 21.3412826 15.9889152 -1.4200113 17.7653917 
#>         78         79         80         81         82         83         84 
#> -3.3613568 21.4672871  9.2354319  9.8772618 -0.1472747 18.7234666 -9.5919059 
#>         85         86         87         88         89         90         91 
#> 10.4575066  7.2662070 -1.8758967  4.5713878 -3.8791275 19.1819438  0.4911183 
#>         92         93         94         95         96         97         98 
#> -0.7629863 27.7153955 35.7256768  9.3233397  9.7363512 24.9163912 19.8377229 
#>         99        100 
#> 11.4892106 20.9790467 
# }