Fit random forest spatial residual models for stream network data 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.
ssn_lmRF(formula, ssn.object, ...)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 spatial stream network object with class SSN.
Additional named arguments to ranger::ranger() or ssn_lm().
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 stream network model object fit to the residuals
(named ssn_lm), 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.
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 ssn_lm(). 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 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.
if (requireNamespace("ranger", quietly = TRUE)) {
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf <- ssn_import(temp_path,
predpts = "CapeHorn", overwrite = TRUE
)
ssn_create_distmat(mf, predpts = "CapeHorn", overwrite = TRUE)
rf_fit <- ssn_lmRF(
Summer_mn ~ ELEV_DEM, mf, tailup_type = "exponential",
additive = "afvArea", num.trees = 50, num.threads = 1, seed = 1
)
print(rf_fit)
head(predict(rf_fit, "CapeHorn"))
}
#> Error in ssn_lmRF(Summer_mn ~ ELEV_DEM, mf, tailup_type = "exponential", additive = "afvArea", num.trees = 50, num.threads = 1, seed = 1): could not find function "ssn_lmRF"