| light_ice {flashlight} | R Documentation |
Individual Conditional Expectation (ICE)
Description
Generates Individual Conditional Expectation (ICE) profiles. An ICE profile shows how the prediction of an observation changes if one or multiple variables are systematically changed across its ranges, holding all other values fixed (see the reference below for details). The curves can be centered in order to increase visibility of interaction effects.
Usage
light_ice(x, ...)
## Default S3 method:
light_ice(x, ...)
## S3 method for class 'flashlight'
light_ice(
x,
v = NULL,
data = x$data,
by = x$by,
evaluate_at = NULL,
breaks = NULL,
grid = NULL,
n_bins = 27L,
cut_type = c("equal", "quantile"),
indices = NULL,
n_max = 20L,
seed = NULL,
use_linkinv = TRUE,
center = c("no", "first", "middle", "last", "mean", "0"),
...
)
## S3 method for class 'multiflashlight'
light_ice(x, ...)
Arguments
x |
An object of class "flashlight" or "multiflashlight". |
... |
Further arguments passed to or from other methods. |
v |
The variable name to be profiled. |
data |
An optional |
by |
An optional vector of column names used to additionally group the results. |
evaluate_at |
Vector with values of |
breaks |
Cut breaks for a numeric |
grid |
A |
n_bins |
Approximate number of unique values to evaluate for numeric |
cut_type |
Should a numeric |
indices |
A vector of row numbers to consider. |
n_max |
If |
seed |
An integer random seed. |
use_linkinv |
Should retransformation function be applied? Default is |
center |
How should curves be centered?
|
Details
There are two ways to specify the variable(s) to be profiled.
Pass the variable name via
vand an optional vector with evaluation pointsevaluate_at(orbreaks). This works for dependence on a single variable.More general: Specify any
gridas adata.framewith one or more columns. For instance, it can be generated by a call toexpand.grid().
The minimum required elements in the (multi-)flashlight are "predict_function", "model", "linkinv" and "data", where the latest can be passed on the fly.
Which rows in data are profiled? This is specified by indices.
If not given and n_max is smaller than the number of rows in data,
then row indices will be sampled randomly from data.
If the same rows should be used for all flashlights in a multiflashlight,
there are two options: Either pass a seed or a vector of indices used to select rows.
In both cases, data should be the same for all flashlights considered.
Value
An object of class "light_ice" with the following elements:
-
dataA tibble containing the results. Can be used to build fully customized visualizations. Column names can be controlled byoptions(flashlight.column_name). -
bySame as inputby. -
vThe variable(s) evaluated. -
centerHow centering was done.
Methods (by class)
-
light_ice(default): Default method not implemented yet. -
light_ice(flashlight): ICE profiles for a flashlight object. -
light_ice(multiflashlight): ICE profiles for a multiflashlight object.
References
Goldstein, A. et al. (2015). Peeking inside the black box: Visualizing statistical learning with plots of individual conditional expectation. Journal of Computational and Graphical Statistics, 24:1 <doi.org/10.1080/10618600.2014.907095>.
See Also
light_profile(), plot.light_ice()
Examples
fit <- lm(Sepal.Length ~ ., data = iris)
fl <- flashlight(model = fit, label = "lm", data = iris)
light_ice(fl, v = "Species")