pred.rfsi | R Documentation |
Function for spatial/spatio-temporal prediction based on Random Forest Spatial Interpolation (RFSI) model (Sekulić et al. 2020).
pred.rfsi(model,
data,
obs.col=1,
data.staid.x.y.z = NULL,
newdata,
newdata.staid.x.y.z = NULL,
z.value = NULL,
s.crs = NA,
newdata.s.crs=NA,
p.crs = NA,
output.format = "data.frame",
cpus = detectCores()-1,
progress = TRUE,
soil3d = FALSE, # soil RFSI
depth.range = 0.1, # in units of depth
no.obs = 'increase',
...)
model |
ranger; An RFSI model made by rfsi function. |
data |
sf-class, sftime-class, SpatVector-class or data.frame; Contains target variable (observations) and covariates used for RFSI prediction. If data.frame object, it should have next columns: station ID (staid), longitude (x), latitude (y), 3rd component - time, depth, ... (z) of the observation, and observation value (obs). |
obs.col |
numeric or character; Column name or number showing position of the observation column in the |
data.staid.x.y.z |
numeric or character vector; Positions or names of the station ID (staid), longitude (x), latitude (y) and 3rd component (z) columns in data.frame object (e.g. c(1,2,3,4)). If |
newdata |
sf-class, sftime-class, SpatVector-class, SpatRaster-class or data.frame; Contains prediction locations and covariates used for RFSI prediction. If data.frame object, it should have next columns: prediction location ID (staid), longitude (x), latitude (y), 3rd component - time, depth, ... (z), and covariates (cov1, cov2, ...). Covariate names have to be the same as in the |
newdata.staid.x.y.z |
numeric or character vector; Positions or names of the prediction location ID (staid), longitude (x), latitude (y) and 3rd component (z) columns in data.frame |
z.value |
vector; A vector of 3rd component - time, depth, ... (z) values if |
s.crs |
st_crs or crs; Source CRS of |
newdata.s.crs |
st_crs or crs; Source CRS of |
p.crs |
st_crs or crs; Projection CRS for |
output.format |
character; Format of the output, data.frame (default), sf-class, sftime-class, SpatVector-class, or SpatRaster-class. |
cpus |
numeric; Number of processing units. Default is detectCores()-1. |
progress |
logical; If progress bar is shown. Default is TRUE. |
soil3d |
logical; If 3D soil modellig is performed and near.obs.soil function is used for finding n nearest observations and distances to them. In this case, z position of the |
depth.range |
numeric; Depth range for location mid depth in which to search for nearest observations (see function near.obs.soil). It's in the mid depth units. Default is 0.1. |
no.obs |
character; Possible values are |
... |
Further arguments passed to predict.ranger function, such as |
A data.frame, sf-class, sftime-class, SpatVector-class, or SpatRaster-class object (depends on output.format
argument) with prediction - pred
or quantile..X.X
(quantile regression) columns.
Aleksandar Sekulic asekulic@grf.bg.ac.rs
Sekulić, A., Kilibarda, M., Heuvelink, G. B., Nikolić, M. & Bajat, B. Random Forest Spatial Interpolation. Remote. Sens. 12, 1687, https://doi.org/10.3390/rs12101687 (2020).
near.obs
rfsi
tune.rfsi
cv.rfsi
library(ranger)
library(sp)
library(sf)
library(terra)
library(meteo)
# prepare data
demo(meuse, echo=FALSE)
meuse <- meuse[complete.cases(meuse@data),]
data = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
fm.RFSI <- as.formula("zinc ~ dist + soil + ffreq")
# fit the RFSI model
rfsi_model <- rfsi(formula = fm.RFSI,
data = data, # meuse.df (use data.staid.x.y.z)
n.obs = 5, # number of nearest observations
cpus = 2, # detectCores()-1,
progress = TRUE,
# ranger parameters
importance = "impurity",
seed = 42,
num.trees = 250,
mtry = 5,
splitrule = "variance",
min.node.size = 5,
sample.fraction = 0.95,
quantreg = FALSE)
# quantreg = TRUE) # for quantile regression
rfsi_model
# OOB prediction error (MSE): 47758.14
# R squared (OOB): 0.6435869
sort(rfsi_model$variable.importance)
sum("obs" == substr(rfsi_model$forest$independent.variable.names, 1, 3))
# Make RFSI prediction
newdata <- terra::rast(meuse.grid)
class(newdata)
# prediction
rfsi_prediction <- pred.rfsi(model = rfsi_model,
data = data, # meuse.df (use data.staid.x.y.z)
obs.col = "zinc",
newdata = newdata, # meuse.grid.df (use newdata.staid.x.y.z)
output.format = "SpatRaster", # "sf", # "SpatVector",
zero.tol = 0,
cpus = 2, # detectCores()-1,
progress = TRUE,
# type = "quantiles", # for quantile regression
# quantiles = c(0.1, 0.5, 0.9) # for quantile regression
)
class(rfsi_prediction)
names(rfsi_prediction)
head(rfsi_prediction)
plot(rfsi_prediction)
plot(rfsi_prediction['pred'])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.