Skip to contents

The prediction averaged over the observed joint distribution of the complement variables, with the variables in S held fixed. This is a marginal of the FITTED surface, not a conditional expectation: it answers "what does the model do if I move x_S", not "what is E of y given x_S".

Usage

morie_esl_partial_dependence(model, X, S, grid = NULL, n_grid = 20L)

Arguments

model

Function taking an (m, p) matrix and returning predictions.

X

Data supplying the complement distribution, n by p.

S

Column indices (1-based) to vary.

grid

Values of x_S to evaluate; defaults to a quantile grid.

n_grid

Grid size when grid is not given.

Value

List with grid, pd, centered, extrapolation_warning.

Details

The average runs over the marginal of the complement, so when x_S and the complement are correlated the model is evaluated at combinations that never occur, and the curve there is extrapolation. extrapolation_warning flags grid points whose synthetic rows sit far from the observed cloud – measured in the JOINT, since every quantile grid point is by construction close to observed x_S values.

References

Friedman, J. H. (2001). Greedy function approximation. Annals of Statistics 29(5), 1189-1232.

Examples

set.seed(1)
X <- matrix(runif(800, -2, 2), ncol = 2)
f <- function(Z) 3 * Z[, 1] + Z[, 2]^2
r <- morie_esl_partial_dependence(f, X, S = 1, n_grid = 9)
abs(stats::coef(stats::lm(r$pd ~ r$grid[, 1]))[[2]] - 3) < 1e-8
#> [1] TRUE