Calculates response- prediction-, partial dependence, and ALE profiles of a (multi-)flashlight with respect to a covariable v
.
light_effects(x, ...)# S3 method for default
light_effects(x, ...)
# S3 method for flashlight
light_effects(
x,
v,
data = NULL,
by = x$by,
stats = c("mean", "quartiles"),
breaks = NULL,
n_bins = 11,
cut_type = c("equal", "quantile"),
use_linkinv = TRUE,
counts_weighted = FALSE,
v_labels = TRUE,
pred = NULL,
pd_indices = NULL,
pd_n_max = 1000,
pd_seed = NULL,
ale_two_sided = TRUE,
...
)
# S3 method for multiflashlight
light_effects(
x,
v,
data = NULL,
breaks = NULL,
n_bins = 11,
cut_type = c("equal", "quantile"),
...
)
An object of class light_effects
with the following elements.
response
A tibble containing the response profiles. Column names can be controlled by options(flashlight.column_name)
.
predicted
A tibble containing the prediction profiles.
pd
A tibble containing the partial dependence profiles.
ale
A tibble containing the ALE profiles.
by
Same as input by
.
v
The variable(s) evaluated.
stats
Same as input stats
.
An object of class flashlight
or multiflashlight
.
Further arguments passed to cut3
resp. formatC
in forming the cut breaks of the v
variable.
The variable name to be profiled.
An optional data.frame
.
An optional vector of column names used to additionally group the results.
Statistic to calculate for the response profile: "mean" or "quartiles".
Cut breaks for a numeric v
. Used to overwrite automatic binning via n_bins
and cut_type
. Ignored if v
is not numeric.
Approximate number of unique values to evaluate for numeric v
. Ignored if v
is not numeric or if breaks
is specified.
Should a numeric v
be cut into "equal" or "quantile" bins? Ignored if v
is not numeric or if breaks
is specified.
Should retransformation function be applied? Default is TRUE.
Should counts be weighted by the case weights? If TRUE, the sum of w
is returned by group.
If FALSE, return group centers of v
instead of labels. Only relevant if v
is numeric with many distinct values. In that case useful if e.g. different flashlights use different data sets.
Optional vector with predictions (after application of inverse link). Can be used to avoid recalculation of predictions over and over if the functions is to be repeatedly called for different v
and predictions are computationally expensive to make. Not implemented for multiflashlight.
A vector of row numbers to consider in calculating partial dependence and ALE profiles. Useful to force all flashlights to use the same basis for calculations of partial dependence and ALE.
Maximum number of ICE profiles to consider for partial depencence and ALE calculation (will be randomly picked from data
).
An integer random seed used to sample ICE profiles for partial dependence and ALE.
If TRUE
, v
is continuous and breaks
are passed or being calculated, then two-sided derivatives are calculated for ALE instead of left derivatives. This aligns the results better with the x labels. More specifically: Usually, local effects at value x are calculated using points between x-e and x. Set ale_two_sided = TRUE
to use points between x-e/2 and x+e/2.
default
: Default method.
flashlight
: Profiles for a flashlight object.
multiflashlight
: Effect profiles for a multiflashlight object.
Note that ALE profiles are being calibrated by (weighted) average predictions. The resulting level might be quite different from the one of the partial dependence profiles.
light_profile
, plot.light_effects
.
fit <- lm(Sepal.Length ~ ., data = iris)
fl <- flashlight(model = fit, label = "iris", data = iris, y = "Sepal.Length")
light_effects(fl, v = "Species")
Run the code above in your browser using DataLab