% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/splmRF.R
\name{splmRF}
\alias{splmRF}
\title{Fit random forest spatial residual models}
\usage{
splmRF(formula, data, ...)
}
\arguments{
\item{formula}{A two-sided linear formula describing the fixed effect structure
of the model, with the response to the left of the \code{~} operator and
the terms on the right, separated by \code{+} operators.}

\item{data}{A data frame or \code{sf} object object that contains
the variables in \code{fixed}, \code{random}, and \code{partition_factor}
as well as geographical information. If an \code{sf} object is
provided with \code{POINT} geometries, the x-coordinates and y-coordinates
are used directly. If an \code{sf} object is
provided with \code{POLYGON} geometries, the x-coordinates and y-coordinates
are taken as the centroids of each polygon.}

\item{...}{Additional named arguments to \code{ranger::ranger()} or \code{\link[=splm]{splm()}}.}
}
\value{
A list with several elements to be used with \code{predict()}. These
elements include the function call (named \code{call}), the random forest object
fit to the mean (named \code{ranger}),
the spatial linear model object fit to the residuals
(named \code{splm} or \code{splm_list}), and an object can contain data for
locations at which to predict (called \code{newdata}). The \code{newdata}
object contains the set of
observations in \code{data} whose response variable is \code{NA}.
If \code{spcov_type} or \code{spcov_initial} (which are passed to \code{\link[=splm]{splm()}})
are length one, the list has class \code{splmRF} and the spatial linear
model object fit to the residuals is called \code{splm}, which has
class \code{splm}. If
\code{spcov_type} or \code{spcov_initial} are length greater than one, the
list has class \code{splmRF_list} and the spatial linear model object
fit to the residuals is called \code{splm_list}, which has class \code{splm_list}.
and contains several objects, each with class \code{splm}.

An \code{splmRF} object to be used with \code{predict()}. There are
three elements: \code{ranger}, the output from fitting the mean model with
\code{ranger::ranger()}; \code{splm}, the output from fitting the spatial
linear model to the ranger residuals; and \code{newdata}, the \code{newdata}
object, if relevant.
}
\description{
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.
}
\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 \code{formula} using \code{ranger::ranger()}. Residuals
are computed and used as the response variable in an intercept-only spatial
linear model fit using \code{\link[=splm]{splm()}}. This model object is intended for use with
\code{predict()} for 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.
}
\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)
}
}
\references{
Fox, E.W., Ver Hoef, J. M., & Olsen, A. R. (2020). Comparing spatial
regression to random forests for large environmental data sets.
\emph{PloS one}, 15(3), e0229509.
}
