plot

Class: LinearModel

Scatter plot or added variable plot of linear model

Syntax

plot(mdl)
h = plot(mdl)

Description

plot(mdl) creates a plot of the fitted linear model. The plot type depends on the number of predictor variables.

  • If there is just one predictor variable, plot creates a scatter plot of the data along with a fitted curve and confidence bounds.

  • If there are multiple predictor variables, plot creates an added variable plot.

  • If there are no predictors, plot creates a histogram of the residuals.

h = plot(mdl) returns handles to the lines in the plot.

Input Arguments

mdl

Linear model, as constructed by fitlm or stepwiselm.

Output Arguments

h

Vector of handles to lines or patches in the plot.

Definitions

Added Variable Plot, Adjusted Response

An added variable plot illustrates the incremental effect on the response of specified terms by removing the effects of all other terms. The slope of the fitted line is the coefficient of the linear combination of the specified terms projected onto the best-fitting direction. The adjusted response includes the constant (intercept) terms, and averages out all other terms.

Examples

expand all

Create an Added Variable Plot

Create a model of car mileage as a function of weight and model year. Then create a plot to see the significance of the model.

Create a linear model of mileage from the carsmall data.

load carsmall
tbl = table(MPG,Weight);
tbl.Year = ordinal(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight^2');

Create an added variable plot.

plot(mdl)

The plot illustrates that the model is significant—a horizontal line does not fit between the confidence bounds.

Alternatives

Use plotAdded to select particular predictors for an added variable plot.

Was this topic helpful?