View source: R/VCR_visualization.R
qresplot | R Documentation |
Draw a quasi residual plot to visualize classification results. The vertical axis of the quasi residual plot shows each case's probability of alternative class (PAC). The horizontal axis shows the feature given as the second argument in the function call.
qresplot(PAC, feat, xlab = NULL, xlim = NULL,
main = NULL, identify = FALSE, gray = TRUE,
opacity = 1, squareplot = FALSE, plotLoess = FALSE,
plotErrorBars = FALSE, plotQuantiles = FALSE,
grid = NULL, probs = c(0.5, 0.75),
cols = NULL, fac = 1, cex = 1,
cex.main = 1.2, cex.lab = 1,
cex.axis = 1, pch = 19)
PAC |
vector with the PAC values of a classification,
typically the |
feat |
the PAC will be plotted versus this data feature. Note that feat does not have to be one of the explanatory variables of the model. It can be another variable, a combination of variables (like a sum or a principal component score), the row number of the cases if they were recorded succesively, etc. |
xlab |
label for the horizontal axis, i.e. the name of variable feat. |
xlim |
limits for the horizontal axis. If |
main |
title for the plot. |
identify |
if |
gray |
logical, if |
opacity |
determines opacity of plotted dots. Value between 0 and 1, where 0 is transparent and 1 is opaque. |
squareplot |
if |
plotLoess |
if |
plotErrorBars |
if |
plotQuantiles |
if |
grid |
only used when |
probs |
only used when |
cols |
only used when plotquantiles is selected.
A vector with the colors of the quantile curves.
If |
fac |
only used when |
cex |
passed on to |
cex.main |
same, for title. |
cex.lab |
same, for labels on horizontal and vertical axes. |
cex.axis |
same, for axes. |
pch |
plot character for the points, defaults to 19. |
coordinates |
a matrix with 2 columns containing the
coordinates of the plotted points. This makes it
easier to add text next to interesting points.
If |
Raymaekers J., Rousseeuw P.J.
Raymaekers J., Rousseeuw P.J.(2021). Silhouettes and quasi residual plots for neural nets and tree-based classifiers. (link to open access pdf)
library(rpart)
data("data_titanic")
traindata <- data_titanic[which(data_titanic$dataType == "train"), -13]
set.seed(123) # rpart is not deterministic
rpart.out <- rpart(y ~ Pclass + Sex + SibSp +
Parch + Fare + Embarked,
data = traindata, method = 'class', model = TRUE)
mytype <- list(nominal = c("Name", "Sex", "Ticket", "Cabin", "Embarked"), ordratio = c("Pclass"))
x_train <- traindata[, -12]
y_train <- traindata[, 12]
vcrtrain <- vcr.rpart.train(x_train, y_train, rpart.out, mytype)
# Quasi residual plot versus age, for males only:
PAC <- vcrtrain$PAC[which(x_train$Sex == "male")]
feat <- x_train$Age[which(x_train$Sex == "male")]
qresplot(PAC, feat, xlab = "Age (years)", opacity = 0.5,
main = "quasi residual plot for male passengers",
plotLoess = TRUE)
text(x = 14, y = 0.60, "loess curve", col = "red", cex = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.