Estimates the partial derivative function for each curve in an ice object.
See Goldstein et al (2013) for further details.
Usage
dice(
ice_obj,
DerivEstimator = NULL,
use_supsmu = FALSE,
verbose = TRUE,
num_cores = 1,
sg_poly_order = 2,
sg_window_size = NULL
)Arguments
- ice_obj
Object of class
ice. This function generates partial derivative estimates for each row inice_obj$ice_curves.- DerivEstimator
Optional function with a single argument
y. Returns the estimated partial derivative of a function sampled at the points (ice_obj$gridpts,y). If NULL, the default uses a Savitzky-Golay filter to estimate the first derivative.- use_supsmu
If
TRUE, uses the oldsupsmubased derivative estimation logic. This is much slower than the default Savitzky-Golay filter.- verbose
If
TRUE, prints messages about the procedure's progress.- num_cores
Integer number of cores to use for parallel derivative estimation. Defaults to 1.
- sg_poly_order
Polynomial order for Savitzky-Golay filter. Default is 2.
- sg_window_size
Window size for Savitzky-Golay filter. Default is 30% of the grid.
Value
A list of class dice with the following elements. Most are passed directly through
from ice_object and exist to enable various plotting facilities.
- d_ice_curves
Matrix of dimension
nrow(Xice)bylength(gridpts). Each row corresponds to an observation's d-ICE curve, estimated at the values ofpredictoringridpts.- xj
The actual values of
predictorobserved in the data in the order ofXice.- actual_deriv
Vector of length
nrow(Xice)containing the estimated partial derivatives at the value of thepredictoractually found inXice.- sd_deriv
Vector of length
length(gridpts)with the cross-observation sd of partial derivative estimates. For instancesd_deriv[1]equalssd(d_ice_curves[,1]).- logodds
Passed from
ice_object. IfTRUE,d_ice_curvesare estimated derivatives of the centered log-odds.- gridpts
Passed from
ice_object.- predictor
Passed from
ice_object.- xlab
Passed from
ice_object.- nominal_axis
Passed from
ice_object.- range_y
Passed from
ice_object.- Xice
Passed from
ice_object.- dpdp
The estimated partial derivative of the PDP.
References
Goldstein, A., Kapelner, A., Bleich, J., and Pitkin, E., Peeking
Inside the Black Box: Visualizing Statistical Learning With Plots of
Individual Conditional Expectation. (2014) Journal of Computational
and Graphical Statistics, in press
See also
ice, dice
Examples
if (FALSE) { # \dontrun{
# same examples as for 'ice', but now create a derivative estimate as well.
require(ICEbox)
require(randomForest)
require(MASS) #has Boston Housing data, Pima
######## regression example
data(Boston) #Boston Housing data
X = Boston
y = X$medv
X$medv = NULL
## build a RF:
bhd_rf_mod = randomForest(X, y)
## Create an 'ice' object for the predictor "age":
bhd.ice = ice(object = bhd_rf_mod, X = X, y = y, predictor = "age", frac_to_build = .1)
# make a dice object:
bhd.dice = dice(bhd.ice)
#### classification example
data(Pima.te) #Pima Indians diabetes classification
y = Pima.te$type
X = Pima.te
X$type = NULL
## build a RF:
pima_rf = randomForest(x = X, y = y)
## Create an 'ice' object for the predictor "skin":
# For classification we plot the centered log-odds. If we pass a predict
# function that returns fitted probabilities, setting logodds = TRUE instructs
# the function to set each ice curve to the centered log-odds of the fitted
# probability.
pima.ice = ice(object = pima_rf, X = X, predictor = "skin", logodds = TRUE,
predictfcn = function(object, newdata){
predict(object, newdata, type = "prob")[, 2]
}
)
# make a dice object:
pima.dice = dice(pima.ice)
} # }