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 
#>  4.6647081 32.2937280 12.4171827 20.0334091  4.6137773 20.9338497 -3.7767627 
#>          8          9         10         11         12         13         14 
#> 10.3723772  7.8501108  9.0635043 -2.8887342  5.9599629 19.2548782 26.8253179 
#>         15         16         17         18         19         20         21 
#> 15.7219905 13.3392745 25.9704929 15.8928768 12.8669760 15.9325344  6.1293825 
#>         22         23         24         25         26         27         28 
#>  7.7215349 12.3805158  1.7211356  2.5122180  2.7523199 10.7403443  6.1422438 
#>         29         30         31         32         33         34         35 
#> 14.6772741  9.1394838  8.9918356 -1.5755322  5.7765686 -3.6979914  9.6750398 
#>         36         37         38         39         40         41         42 
#> 12.6131454 13.3057213  9.5178131 11.9364494 18.9649011 13.0870195 35.1439319 
#>         43         44         45         46         47         48         49 
#> 19.5160789 26.3875611 -1.2161375  3.3560655 -1.4073731  7.6184210 19.6736354 
#>         50         51         52         53         54         55         56 
#> 13.0866364 39.9645591 16.6260932  0.7717388  2.6775865  0.9928212 14.9730969 
#>         57         58         59         60         61         62         63 
#> 15.0050216 -7.5984904 26.8405839  8.9867037  8.7887695 24.8789255 -7.5847903 
#>         64         65         66         67         68         69         70 
#> 21.4436460 32.0487576  6.8317962  2.7597476  2.9478836  5.9237449  9.8088981 
#>         71         72         73         74         75         76         77 
#>  6.1561882 10.2314572  1.8431124  8.6310116 15.2053649 -0.5291756 26.1073539 
#>         78         79         80         81         82         83         84 
#>  5.3472115  9.0737273 18.6513870 12.2118785  9.1529688  2.0959976  2.4863667 
#>         85         86         87         88         89         90         91 
#>  7.1176109  9.3876520 -2.5349409 -0.6536736 -1.2594729 20.6462609  8.4969729 
#>         92         93         94         95         96         97         98 
#> 17.1992093  8.9246054 35.1800119  9.4604696  8.4838238 23.1624371 20.5977136 
#>         99        100 
#> 12.9440470  8.7627524 
# }