predsplot {classmap} | R Documentation |
Make a predictions plot
Description
Plots the prediction terms of a regression, together with the total prediction. The input variables of the regression can be numerical, categorical, logical and character, and are visualized by histograms, densities, or bar plots. The regression model can be linear or generalized linear. The regression formula in lm() or glm() may contain transformations and interactions. The plot shows all cases in the data, but can also be made for a single case, either in-sample or out-of-sample, to explain its prediction.
Usage
predsplot(fit, maxnpreds = 8, sort.by.stdev = TRUE, displaytype = "histogram",
totalpred.type = "response", trunc.totalpred = TRUE, casetoshow = NULL,
staircase = FALSE, verbose = TRUE, maxchar.level = 5, nfact = 8, main = NULL,
cex.main = 1, xlab = NULL, ylab = NULL, vlinewidth = 0.25, hlinewidth = 0.25,
drawborder = TRUE, borderwidth = 1.0, densitycolors = NULL, predupcolor = "red",
preddowncolor = "blue", predpointsize = 3, draw.segments = TRUE,
predsegmentwidth = 0.8, profile = FALSE, bw = "nrd0", adjust = 1)
Arguments
fit |
|
maxnpreds |
the maximal number of prediction terms to plot. When there are more prediction terms than this, those with smallest standard deviations are combined. |
sort.by.stdev |
if |
displaytype |
when |
totalpred.type |
when fit is a |
trunc.totalpred |
if |
casetoshow |
if not |
staircase |
if |
verbose |
if |
maxchar.level |
only the first maxchar.level characters of the categorical levels are displayed. |
nfact |
if a numeric input variable has at most
|
main |
main title of the plot. |
cex.main |
its size. |
xlab |
horizontal legend. Its size can be changed by setting the height and width of the plot. |
ylab |
vertical legend. Its size can be changed by setting the height and width of the plot. |
vlinewidth |
width of the vertical lines. |
hlinewidth |
width of the horizontal line. |
drawborder |
if |
borderwidth |
width of the border. Defaults to 1. |
densitycolors |
a vector with 4 colors. The first is
for numeric input variables pointing up,
the second for numeric input variables
pointing down, the third for
prediction terms without orientation
and the total prediction, and the
fourth for factors. If |
predupcolor |
the color of a positive prediction for casetoshow. |
preddowncolor |
the color of a negative prediction for casetoshow. |
predpointsize |
the size of the points displaying the predictions for casetoshow. |
draw.segments |
if |
predsegmentwidth |
the width of that line segment. |
profile |
when casetoshow is not |
bw |
the bandwidth of the density estimation,
only used when |
adjust |
multiplier of the bandwidth of the density
estimation, only used when |
Value
A list with items
p |
the predictions plot, which is a ggplot2 object. |
totpred |
vector with the total linear prediction of all cases for which it can be computed. |
centercept |
the centercept, which is the total linear prediction when all prediction terms have their average value. |
predterms |
matrix of cases by prediction terms. |
predsummary |
data frame with the standard deviation of each prediction term and the total linear prediction. |
casetotpred |
a number, the total linear prediction for casetoshow if one is given. |
casepredterms |
a vector with the values of the prediction terms for casetoshow. |
casesummary |
data frame which shows all prediction terms for casetoshow together with the centercept, total linear prediction, and for a glm fit also the total prediction in response units. |
Author(s)
Rousseeuw, P.J.
References
Rousseeuw, P.J. (2025). Explainable Linear and Generalized Linear Models by the Predictions Plot https://arxiv.org/abs/2412.16980v2 (open access).
See Also
Examples
data(data_titanic)
attach(data_titanic)
survival = y
Pclass = factor(Pclass, unique(Pclass))
Sex = factor(Sex, labels = c("F","M"))
fit <- glm(survival ~ Sex + Age + SibSp + Parch + Pclass, family=binomial)
predsplot(fit, main = "Titanic data", displaytype = "density")
# For more examples, we refer to the vignette:
## Not run:
vignette("predsplot_examples")
## End(Not run)