For a continuous predictor, gg_ale_rfsrc bins the observed values
into n_eval quantile-based intervals. Within each bin, every
observation's predictor value is replaced first with the bin's lower edge
and then with its upper edge (all other predictors held at that
observation's own values), and the average change in prediction is the
bin's local effect. These local effects are accumulated (cumulatively
summed) across bins and centered to have a weighted mean of zero, giving a
curve that is directly comparable to gg_partial_rfsrc's
output but immune to extrapolation into implausible predictor
combinations.
For a categorical predictor, the model's own factor level order is used
as the "grid": the local effect for the step from level \(k\) to level
\(k+1\) is averaged over the observations at both levels, each predicted
at level \(k+1\) and at level \(k\), so an observation at an interior
level serves two steps. Relevel the predictor before fitting the forest to
control this ordering.
Supplying xvar2.name switches to second-order (interaction) ALE
between xvar.names and xvar2.name, isolating the part of
their joint effect that is not explained by either variable's own main
effect. It is the ALE analogue of an interaction term, computed on a
2-D grid of bins using the same local-perturbation idea. Following Apley
and Zhu, each variable's main effect is estimated from the accumulated
surface by accumulating its local differences along that variable's axis,
weighted by the observations in each cell, and subtracted; the surface is
then centred to a weighted mean of zero. A cell with no observations takes
the local effect of the nearest cell that has some. A purely additive
forest returns an all-zero surface.