View source: R/error.threshold.plot.R
error.threshold.plot | R Documentation |
error.threshold.plot
takes a single model and plots the sensitivity and specificity as a function of threshold. It will optionally add other error statistics such as PCC and/or Kappa to the plot. Optionally, it will also optimize the choice of threshold by several criteria, return the results as a dataframe, and mark the optimized thresholds on the plot.
error.threshold.plot(DATA, threshold = 101, which.model = 1, na.rm = FALSE, xlab = "Threshold", ylab = "Accuracy Measures", main = NULL, model.names = NULL, color = NULL, line.type = NULL, lwd = 1, plot.it = TRUE, opt.thresholds = NULL, opt.methods = NULL, req.sens, req.spec, obs.prev = NULL, smoothing = 1, vert.lines = FALSE, add.legend = TRUE, legend.text = legend.names, legend.cex = 0.8, add.opt.legend = TRUE, opt.legend.text = NULL, opt.legend.cex = 0.7, pch = NULL, FPC, FNC)
DATA |
a matrix or dataframe of observed and predicted values where each row represents one plot and where columns are:
| ||||||||||||||||||||||||||||||||||||
threshold |
cutoff values between zero and one used for translating predicted probabilities into 0 /1 values, defaults to 0.5. It can be a single value between zero and one, a vector of values between zero and one, or a positive integer representing the number of evenly spaced thresholds to calculate. | ||||||||||||||||||||||||||||||||||||
which.model |
a number indicating which model from | ||||||||||||||||||||||||||||||||||||
na.rm |
a logical indicating whether missing values should be removed | ||||||||||||||||||||||||||||||||||||
xlab |
a title for the x axis | ||||||||||||||||||||||||||||||||||||
ylab |
a title for the y axis | ||||||||||||||||||||||||||||||||||||
main |
an overall title for the plot | ||||||||||||||||||||||||||||||||||||
model.names |
a vector of the names of each model included in | ||||||||||||||||||||||||||||||||||||
color |
should each error statistic be plotted in a different color. It can be a logical value (where | ||||||||||||||||||||||||||||||||||||
line.type |
should each model be plotted in a different line type. It can be a logical value (where | ||||||||||||||||||||||||||||||||||||
lwd |
line width | ||||||||||||||||||||||||||||||||||||
plot.it |
a logical indicating if a graphical plot should be produced | ||||||||||||||||||||||||||||||||||||
opt.thresholds |
logical indicating whether the optimal thresholds should be calculated and plotted, or a vector specifying thresholds to plot | ||||||||||||||||||||||||||||||||||||
opt.methods |
what methods should be used to optimize thresholds. Given either as a vector of method names or method numbers. Possible values are:
| ||||||||||||||||||||||||||||||||||||
req.sens |
a value between zero and one giving the user defined required sensitivity. Only used if | ||||||||||||||||||||||||||||||||||||
req.spec |
a value between zero and one giving the user defined required sspecificity. Only used if | ||||||||||||||||||||||||||||||||||||
obs.prev |
observed prevalence for | ||||||||||||||||||||||||||||||||||||
smoothing |
smoothing factor for maximizing/minimizing. Only used if | ||||||||||||||||||||||||||||||||||||
vert.lines |
a logical where: | ||||||||||||||||||||||||||||||||||||
add.legend |
logical indicating if a legend for accuracy statistics should be included on the plot | ||||||||||||||||||||||||||||||||||||
legend.text |
a vector of text for accuracy statistics legend. Defaults to name of each accuracy statistic. | ||||||||||||||||||||||||||||||||||||
legend.cex |
cex for presence/absence legend | ||||||||||||||||||||||||||||||||||||
add.opt.legend |
logical indicating if a legend for optimal threshold criteria should be included on the plot | ||||||||||||||||||||||||||||||||||||
opt.legend.text |
a vector of text for optimimal threshold criteria legend. Defaults to text corresponding to 'opt.methods'. | ||||||||||||||||||||||||||||||||||||
opt.legend.cex |
cex for optimization criteria legend | ||||||||||||||||||||||||||||||||||||
pch |
plotting "character", i.e., symbol to use for the thresholds specified in | ||||||||||||||||||||||||||||||||||||
FPC |
False Positive Costs, or for C/B ratio C = 'net costs of treating nondiseased individuals'. | ||||||||||||||||||||||||||||||||||||
FNC |
False Negative Costs, or for C/B ratio B = 'net benefits of treating diseased individuals'. |
error.threshold.plot
serves two purposes. First, if plot.it
= TRUE
, it produces a graphical plot. Second, if opt.thresholds
= TRUE
it will find optimal thresholds by several criteria. These optimal thresholds, along with basic accuracy measures for each type of optimal threshold will be returned as a dataframe. If a plot is produced, these optimal thresholds will be added to the plot.
The graphical plot will always include lines showing sensitivity and specificity as a function of threshold. In addition, for opt.methods
= "MaxKappa"
, "MaxPCC"
, "MinROCdist"
, or "MaxSens+Spec"
additional lines will be added to show the statistic being maximized/minimized.
These lines will be added to graph even if opt.thresholds
= FALSE
. So for example, to produce a graph showing sensitivity, specificity, and Kappa as functions of threshold, with out marking the optimal thresholds, set opt.thresholds
= FALSE
, and opt.methods
= "MaxKappa"
.
See optimal.thresholds for more details on the optimization methods, and on the arguments ReqSens
, ReqSpec
, obs.prev
, smoothing
, FPC
, and FNC
.
When opt.thresholds
= TRUE
, the default is to plot the optimal thresholds directly along the corresponding error statistics (or along the sensitivity line if the method has no corresponding error statistic). If the argument vert.lines
= TRUE
, a vertical line is drawn at each optimal threshold, and the lines are labeled across the top of the plot.
Note: if too many methods are included in opt.methods
, the graph will get very crowded.
If plot.it
= TRUE
creates a graphical plot.
If opt.thresholds
= TRUE
, returns a dataframe of information about the optimal thresholds where:
[,1] | legend.names | type of optimal threshold |
[,2] | threshold | optimal threshold |
[,3] | PCC | at that threshold |
[,4] | sensitivity | at that threshold |
[,5] | specificity | at that threshold |
[,6] | Kappa | at that threshold |
Elizabeth Freeman eafreeman@fs.fed.us
optimal.thresholds, presence.absence.accuracy, roc.plot.calculate, presence.absence.summary
data(SIM3DATA) error.threshold.plot(SIM3DATA,opt.methods=c(1,2,5)) error.threshold.plot( SIM3DATA, which.model=2, opt.thresholds=TRUE, opt.methods=c("Default", "Sens=Spec", "MinROCdist"), vert.lines=TRUE) error.threshold.plot( SIM3DATA, threshold=101, which.model=2, na.rm=TRUE, xlab="Threshold", ylab="Accuracy Measures", main="Error Rate verses Threshold", model.names=NULL, pch=NULL, color= c(3,5,7), line.type=NULL, lwd=1, plot.it=TRUE, opt.thresholds=TRUE, opt.methods=1:4, req.sens=0.85, req.spec=0.85, obs.prev=NULL, smoothing=1, vert.lines=FALSE, add.legend=TRUE, legend.cex=0.8)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.