.ale {effectplots}R Documentation

Barebone Accumulated Local Effects (ALE)

Description

This is a barebone implementation of Apley's ALE intended for developers. To get more information on ALE, see ale().

Usage

.ale(
  object,
  v,
  data,
  breaks,
  right = TRUE,
  pred_fun = stats::predict,
  trafo = NULL,
  which_pred = NULL,
  bin_size = 200L,
  w = NULL,
  g = NULL,
  ...
)

Arguments

object

Fitted model.

v

Variable name in data to calculate ALE.

data

Matrix or data.frame.

breaks

Breaks for ALE calculation.

right

Should bins specified via breaks be right-closed? The default is TRUE.

pred_fun

Prediction function, by default stats::predict. The function takes three arguments (names irrelevant): object, data, and ....

trafo

How should predictions be transformed? A function or NULL (default). Examples are log (to switch to link scale) or exp (to switch from link scale to the original scale).

which_pred

If the predictions are multivariate: which column to pick (integer or column name). By default NULL (picks last column).

bin_size

Maximal number of observations used per bin. If there are more observations in a bin, bin_size indices are randomly sampled. The default is 200.

w

Optional vector with case weights.

g

For internal use. The result of qF(findInterval(...)). By default NULL.

...

Further arguments passed to pred_fun(), e.g., type = "response" in a glm() or (typically) prob = TRUE in classification models.

Value

Vector of ALE values in the same order as breaks[-length(breaks)].

References

Apley, Daniel W., and Jingyu Zhu. 2020. Visualizing the Effects of Predictor Variables in Black Box Supervised Learning Models. Journal of the Royal Statistical Society Series B: Statistical Methodology, 82 (4): 1059–1086. doi:10.1111/rssb.12377.

See Also

partial_dependence()

Examples

fit <- lm(Sepal.Length ~ ., data = iris)
v <- "Sepal.Width"
.ale(fit, v, data = iris, breaks = seq(2, 4, length.out = 5))

[Package effectplots version 0.1.0 Index]