Skip to contents

Predicted values based on a random forest spatial residual fitted model object.

Usage

# S3 method for spmodRF
predict(object, newdata, local, ...)

# S3 method for spmodRF_list
predict(object, newdata, local, ...)

Arguments

object

A fitted model object from splmRF() or spautorRF().

newdata

A data frame or sf object in which to look for variables with which to predict. If a data frame, newdata must contain all variables used by formula(object) and all variables representing coordinates. If an sf object, newdata must contain all variables used by formula(object) and coordinates are obtained from the geometry of newdata. If omitted, missing data from the fitted model object are used.

local

A optional logical or list controlling the big data approximation to the spatial residual prediction. If omitted, local is set to TRUE or FALSE based on the sample size of the fitted model object and/or the prediction size of newdata -- if the sample size or prediction size exceeds 5000, local is set to TRUE, otherwise it is set to FALSE. If FALSE, no big data approximation is implemented. If a list is provided, the following arguments detail the big data approximation:

  • method: The big data approximation method. If method = "all", all observations are used and size is ignored. If method = "distance", the size data observations closest (in terms of Euclidean distance) to the observation requiring prediction are used. If method = "covariance", the size data observations with the highest covariance with the observation requiring prediction are used. If random effects and partition factors are not used in estimation and the spatial covariance function is monotone decreasing, "distance" and "covariance" are equivalent. The default is "covariance". Only used with models fit using splm().

  • size: The number of data observations to use when method is "distance" or "covariance". The default is 50. Only used with models fit using splm().

  • parallel: If TRUE, parallel processing via the parallel package is automatically used. The default is FALSE.

  • ncores: If parallel = TRUE, the number of cores to parallelize over. The default is the number of available cores on your machine.

When local is a list, at least one list element must be provided to initialize default arguments for the other list elements. If local is TRUE, defaults for local are chosen such that local is transformed into list(size = 50, method = "covariance", parallel = FALSE).

...

Other arguments to ranger::predict.ranger()

Value

For spmodRF objects, a vector of predictions. For spmodRF_list

objects, a list that contains relevant quantities for each spmodRF object.

Details

For spmodRF objects, the random forest prediction is combined with the (empirical) best linear unbiased prediction for the residual. Fox Et al. call this approach random forest regression Kriging. For spmodRF_list objects, predictions are returned for each spmodRF object.

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 
#>  1.43218460 28.53080893  8.03837627 10.17497586 10.81308166 36.46710057 
#>           7           8           9          10          11          12 
#>  0.04473233 12.29349234 16.17456383  7.28704817 -7.21577885  8.18800373 
#>          13          14          15          16          17          18 
#> -5.64281665 13.98306496 17.33658907 19.59547121 21.46132654  7.67508539 
#>          19          20          21          22          23          24 
#>  1.28151885 29.06665010 -0.12472119  5.90915740 -6.54188061  5.54303771 
#>          25          26          27          28          29          30 
#>  0.06576118  5.21284097  9.29580971  0.44480140 19.08291198  0.91680447 
#>          31          32          33          34          35          36 
#> -3.00372224 -0.34021944  5.41896099 -0.78675097 -1.32314237  4.51313058 
#>          37          38          39          40          41          42 
#> 16.10495816  0.34091663  4.10564821  7.24159842  5.39811507 18.30770762 
#>          43          44          45          46          47          48 
#> 16.63568037 29.08105684  9.71542421 17.50411510 10.51016683  9.52026083 
#>          49          50          51          52          53          54 
#> 25.73776270  1.86531098 26.41290240  5.51289702  9.02463067  6.75658990 
#>          55          56          57          58          59          60 
#> -0.69409482  9.15857382 31.73881375 -4.59133446 12.52464094 20.29690552 
#>          61          62          63          64          65          66 
#> 23.91502544 13.81611466 14.28972993 13.33502107 28.90004478  3.61744285 
#>          67          68          69          70          71          72 
#>  6.79289269  6.88577532 19.31395010  9.08781581 11.05990511 26.47688227 
#>          73          74          75          76          77          78 
#>  9.58579462  1.65772917  5.82828905  9.17553608 14.32630665 -5.38173628 
#>          79          80          81          82          83          84 
#> 15.24503222 17.08191480 24.89500076 -1.05309265 18.11117474  3.89109963 
#>          85          86          87          88          89          90 
#>  7.74298803 -2.52345210  7.90531001 -2.79257361 -2.26919797 21.82420656 
#>          91          92          93          94          95          96 
#>  2.23046312 10.19913397  9.90299107 31.14718744  7.36980655 23.52814022 
#>          97          98          99         100 
#> 14.78094089 15.96284146 28.32926543 22.13019804 
# }