Two approaches are available. The default, on-the-fly imputation
(OTFI), handles missing values during tree construction and obtains
final imputations from terminal nodes. Supplying mf.q selects
missForest, which repeatedly uses the other variables to impute each
variable or group of variables with missing values. Both approaches
support numeric and categorical data. The function returns the
imputed data frame; fitted forests and performance summaries are not
returned.
On-the-fly imputation (OTFI)
OTFI is the approach underlying na.action = "na.impute" in
rfsrc and predict.rfsrc. Tang and
Ishwaran (2017, Sections 2.3--2.4) describe the method for both the
supervised and unsupervised case.
Split statistics are calculated from the observed values of the
variables involved. If an observation is missing the value of the
chosen splitting variable, a value is drawn from that variable's
observed inbag values in the node to determine its daughter node.
This draw is temporary: it is discarded after assignment, and the
entry is treated as missing again at the next node. Final
replacements are obtained separately from observed values in the
terminal nodes and combined across trees.
With a response formula, OTFI uses supervised splitting guided by
the specified outcome. For example, Ozone ~ . uses Ozone
to guide the splits while imputing missing responses and
predictors.
With no formula, OTFI uses unsupervised splitting to learn
relationships among the variables. At each node, each of mtry
candidate splitting variables is evaluated against ytry
randomly selected pseudo-responses using a multivariate composite
splitting rule. The best split is selected.
Additionally, for unsupervised data, setting splitrule =
"auto" implements a autoencoder type method which regresses
variables against themselves. Temporary copies serve as multivariate
responses, and the original variables serve as predictors. Missing
entries remain missing in both copies for OTFI to process. All
response variables are used by default (ytry = p). The
temporary responses are discarded after imputation; only the
completed original variables are returned or used in the optional
final sweep. Other splitrule settings are ignored when the
formula is omitted.
nimpute controls the number of OTFI iterations. With a
formula, splitrule = "random" can be used for completely
random splitting.
missForest
missForest is an unsupervised imputation procedure in the sense
that no outcome needs to be designated: every variable can be
imputed using the others. Its individual forests use supervised
regression or classification. The formula argument is
ignored; an outcome column included in data is treated like
any other variable.
The implementation first fills missing values using a small forest
with completely random splitting. These initial imputations supply
values for the predictors in subsequent fits.
With mf.q = 1 and always.use = NULL, the method
follows the variable-by-variable approach of Stekhoven and
Buehlmann (2012). For each variable with missing values, a forest
is fit using the rows where that variable was observed. Its
missing entries are replaced by predictions from this forest.
Later fits use the imputations already updated for earlier
variables, and the process repeats.
The multivariate extension groups variables with missing values
and imputes each group using the remaining variables (Tang and
Ishwaran, 2017, Section 2.5). Group sizes are approximate and
controlled by mf.q. Within each group, response entries
that were originally missing are set back to missing, while the
current imputations remain available in the predictors. A forest
with multivariate composite splitting imputes the responses.
Groups are formed anew at each iteration. Variables named in
always.use are added to every response group.
For both versions, iteration is controlled by max.iter and
eps. After each pass, changes at originally missing
entries are summarized by factor disagreement and scaled numeric
changes, averaged over the variables. Iteration stops when this
measure fails to decrease by at least eps, or when
max.iter is reached. The last completed pass is retained.
Data handling and optional refinements
Rows and columns with no observed values are removed before
imputation. If no missing values remain, the data are returned
without fitting a forest. If the entire data frame is missing,
it is returned without imputation.
For large data sets, blocks restricts the main imputation
fits to separate groups of rows. This can reduce computation but
limits the information available to each fit. Autoencoder fits use
only response variables with observed values in that block and limit
ytry accordingly. The missForest initialization and optional
final sweep use all retained rows.
Setting full.sweep = TRUE adds a final pass after either
method. Each variable that originally had missing values is fit
on its observed rows using the current imputed predictors. Only
its originally missing entries are replaced, and later fits use
earlier updates from the sweep. Sweep controls are supplied in
full.sweep.options; see ... above.
With restore.integer = TRUE, integer support is determined
from the original data before imputation. Numeric values are
compared with the nearest integer using a fixed absolute
floating-point tolerance. Rounding applies only to imputed
entries: after the missForest initialization, before and after
the optional final sweep, and before the data are returned.
Values are not rounded between the individual missForest updates.