Learn R Programming

classmap (version 1.2.6)

predscor: Draws a predictions correlation plot, which visualizes the correlations between the prediction terms in a regression fit.

Description

Computes the correlations between the prediction terms in a regression fit, and displays them graphically in a way that takes the standard deviations of the prediction terms into account. The input variables of the regression can be numerical, categorical, logical and character, and the regression model can be linear or generalized linear. The regression formula in lm or glm may contain transformations and interactions.

Usage

predscor(fit, maxnpreds = 8, sort.by.stdev = TRUE, adj.order = FALSE,
cell.length = "stdev", plot.abs.cor = FALSE, palette = NULL,
diagonalcolor = "black")

Value

A list containing

cormat

the correlation matrix of the prediction terms.

predterms

matrix of cases by prediction terms.

predsummary

data frame with the standard deviation of each prediction term and the total linear prediction.

Arguments

fit

an output object of lm or glm.

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 TRUE, sorts the prediction terms by decreasing standard deviation.

adj.order

if TRUE, this modifies the order of the prediction terms in an attempt to bring highly correlated prediction terms close to each other in the predscor display. If sort.by.stdev is TRUE, this happens after that sorting.

cell.length

if "stdev", the sides of the square cells on the diagonal of the correlation matrix are proportional to the standard deviation of their prediction term. If "sqrt" they are proportional to the square root of the standard deviation. If "equal" all sides are the same.

plot.abs.cor

if FALSE, the default, positive and negative correlations are shown in different colors, typically red and blue. If TRUE the absolute values of the correlations are shown.

palette

a vector with colors to display correlations ranging from -1 to 1. If NULL, the default palette shows positive correlations in red, negative correlations in blue, and uses white for correlation zero.

diagonalcolor

color of the cells on the diagonal of the correlation matrix. The default is "black".

Author

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

predsplot

Examples

Run this code
data(data_titanic)
attach(data_titanic)
Pclass = factor(Pclass, unique(Pclass))
Sex = factor(Sex, labels = c("F","M"))
fit <- glm(y ~ Sex + Age + SibSp + Parch + Pclass, family=binomial)
predscor(fit)

# For more examples, we refer to the vignette:
if (FALSE) {
vignette("predsplot_examples")
}

Run the code above in your browser using DataLab