Description Usage Arguments Details Value Author(s) See Also Examples
For classification models, this function creates a 'calibration plot' that describes how consistent model probabilities are with observed event rates.
1 2 3 4 5 6 7 8 9 10 11 12 | calibration(x, ...)
## S3 method for class 'formula'
calibration(x, data = NULL,
class = NULL,
cuts = 11, subset = TRUE,
lattice.options = NULL, ...)
## S3 method for class 'calibration'
xyplot(x, data, ...)
panel.calibration(...)
|
x |
a |
data |
For |
class |
a character string for the class of interest |
cuts |
the number of splits of the data are used to create the plot. By default, it uses as many cuts as there are rows in |
subset |
An expression that evaluates to a logical or integer indexing vector. It is evaluated in |
lattice.options |
A list that could be supplied to |
... |
options to pass through to |
calibration.formula
is used to process the data and xyplot.calibration
is used to create the plot.
To construct the calibration plot, the following steps are used for each model:
The data are split into cuts - 1
roughly equal groups by their class probabilities
the number of samples with true results equal to class
are determined
the event rate is determined for each bin
xyplot.calibration
produces a plot of the observed event rate by the mid-point of the bins.
This implementation uses the lattice function xyplot
, so plot elements can be changed via panel functions, trellis.par.set
or other means. calibration
uses the panel function panel.calibration
by default, but it can be changed by passing that argument into xyplot.calibration
.
The following elements are set by default in the plot but can be changed by passing new values into xyplot.calibration
: xlab = "Bin Midpoint"
, ylab = "Observed Event Percentage"
, type = "o"
, ylim = extendrange(c(0, 100))
,xlim = extendrange(c(0, 100))
and panel = panel.calibration
calibration.formula
returns a list with elements:
data |
the data used for plotting |
cuts |
the number of cuts |
class |
the event class |
probNames |
the names of the model probabilities |
xyplot.calibration
returns a lattice object
Max Kuhn, some lattice code and documentation by Deepayan Sarkar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ## Not run:
data(mdrr)
mdrrDescr <- mdrrDescr[, -nearZeroVar(mdrrDescr)]
mdrrDescr <- mdrrDescr[, -findCorrelation(cor(mdrrDescr), .5)]
inTrain <- createDataPartition(mdrrClass)
trainX <- mdrrDescr[inTrain[[1]], ]
trainY <- mdrrClass[inTrain[[1]]]
testX <- mdrrDescr[-inTrain[[1]], ]
testY <- mdrrClass[-inTrain[[1]]]
library(MASS)
ldaFit <- lda(trainX, trainY)
qdaFit <- qda(trainX, trainY)
testProbs <- data.frame(obs = testY,
lda = predict(ldaFit, testX)$posterior[,1],
qda = predict(qdaFit, testX)$posterior[,1])
calibration(obs ~ lda + qda, data = testProbs)
calPlotData <- calibration(obs ~ lda + qda, data = testProbs)
calPlotData
xyplot(calPlotData, auto.key = list(columns = 2))
## End(Not run)
|
Loading required package: lattice
Loading required package: ggplot2
Call:
calibration.formula(x = obs ~ lda + qda, data = testProbs)
Models: lda, qda
Event: Active
Cuts: 11
Call:
calibration.formula(x = obs ~ lda + qda, data = testProbs)
Models: lda, qda
Event: Active
Cuts: 11
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.