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(...)
lattice
formula (see xyplot
for syntax) where the left-hand side of the formula is a factor class variable of the observed outcome and the right-hand side specifies one or model calibration.formula
, a data frame (or more precisely, anything that is a valid envir
argument in eval
, e.g., a list or an environment) containing values for any variables in the formula, as well as groups
data
data
. Only the resulting rows of data
are used for the plot.lattice.options
xyplot
or the panel function (not used in calibration.formula
).calibration.formula
returns a list with elements:xyplot.calibration
returns a 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:
cuts - 1
roughly equal groups by their class probabilitiesclass
are determinedxyplot.calibration
produces a plot of the observed event rate by the mid-point of the bins. This implementation uses the 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 folowing 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
xyplot
, trellis.par.set
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))
Run the code above in your browser using DataLab