lift
Lift Plot
For classification models, this function creates a 'lift plot' that describes how well a model ranks samples for one class
 Keywords
 hplot
Usage
lift(x, ...)
"lift"(x, data = NULL, class = NULL, subset = TRUE, lattice.options = NULL, cuts = NULL, labels = NULL, ...)
"xyplot"(x, data, plot = "gain", values = NULL, ...)
Arguments
 x

a
lattice
formula (seexyplot
for syntax) where the lefthand side of the formula is a factor class variable of the observed outcome and the righthand side specifies one or model columns corresponding to a numeric ranking variable for a model (e.g. class probabilities). The classification variable should have two levels.  data

For
lift.formula
, a data frame (or more precisely, anything that is a validenvir
argument ineval
, e.g., a list or an environment) containing values for any variables in the formula, as well asgroups
andsubset
if applicable. If not found indata
, or ifdata
is unspecified, the variables are looked for in the environment of the formula. This argument is not used forxyplot.lift
.  class
 a character string for the class of interest
 subset

An expression that evaluates to a logical or integer indexing vector. It is evaluated in
data
. Only the resulting rows ofdata
are used for the plot.  lattice.options

A list that could be supplied to
lattice.options
 cuts

If a single value is given, a sequence of values between 0 and 1 are created with length
cuts
. If a vector, these values are used as the cuts. IfNULL
, each unique value of the model prediction is used. This is helpful when the data set is large.  labels
 A named list of labels for keys. The list should have an element for each term on the righthand side of the formula and the names should match the names of the models.
 plot
 Either "gain" (the default) or "lift". The former plots the number of samples called events versus the event rate while the latter shows the event cutoff versus the lift statistic.
 values

A vector of numbers between 0 and 100 specifying reference values for the percentage of samples found (i.e. the yaxis). Corresponding points on the xaxis are found via interpolation and line segments are shown to indicate how many samples must be tested before these percentages are found. The lines use either the
plot.line
orsuperpose.line
component of the current lattice theme to draw the lines (depending on whether groups were used. These values are only used whentype = "gain"
.  ...

options to pass through to
xyplot
or the panel function (not used inlift.formula
).
Details
lift.formula
is used to process the data and xyplot.lift
is used to create the plot.
To construct data for the the lift and gain plots, the following steps are used for each model:
 The data are ordered by the numeric model prediction used on the righthand side of the model formula
 Each unique value of the score is treated as a cut point
 The number of samples with true results equal to
class
are determined  The lift is calculated as the ratio of the percentage of samples in each split corresponding to
class
over the same percentage in the entire data set
lift
with plot = "gain"
produces a plot of the cumulative lift values by the percentage of samples evaluated while plot = "lift"
shows the cut point value versus the lift statistic.
This implementation uses the lattice function xyplot
, so plot elements can be changed via panel functions, trellis.par.set
or other means. lift
uses the panel function panel.lift2
by default, but it can be changes using update.trellis
(see the examples in panel.lift2
).
The following elements are set by default in the plot but can be changed by passing new values into xyplot.lift
: xlab = "% Samples Tested"
, ylab = "% Samples Found"
, type = "S"
, ylim = extendrange(c(0, 100))
and xlim = extendrange(c(0, 100))
.
Value
 data
 the data used for plotting
 cuts
 the number of cuts
 class
 the event class
 probNames
 the names of the model probabilities
 pct
 the baseline event rate
lift.formula
returns a list with elements:
xyplot.lift
returns a lattice object
See Also
Examples
set.seed(1)
simulated < data.frame(obs = factor(rep(letters[1:2], each = 100)),
perfect = sort(runif(200), decreasing = TRUE),
random = runif(200))
lift1 < lift(obs ~ random, data = simulated)
lift1
xyplot(lift1)
lift2 < lift(obs ~ random + perfect, data = simulated)
lift2
xyplot(lift2, auto.key = list(columns = 2))
xyplot(lift2, auto.key = list(columns = 2), value = c(10, 30))
xyplot(lift2, plot = "lift", auto.key = list(columns = 2))