plotAdded

Class: LinearModel

Added variable plot or leverage plot for linear model

Syntax

plotAdded(mdl)
plotAdded(mdl,coef)
h = plotAdded(mdl,...)
h = plotAdded(mdl,coef,Name,Value)

Description

plotAdded(mdl) produces a generalized added variable plot for all terms in mdl except the constant term.

plotAdded(mdl,coef) produces an added variable plot for the coef terms in mdl, after adjusting for all other terms.

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

h = plotAdded(mdl,coef,Name,Value) plots with additional options specified by one or more Name,Value pair arguments.

Tips

  • For many plots, the Data Cursor tool in the figure window displays the x and y values for any data point, along with the observation name or number.

Input Arguments

mdl

Linear model, as constructed by fitlm or stepwiselm.

coef

Coefficients in mdl. Represent as:

  • String giving a single coefficient name

  • Vector of coefficient numbers in the mdl.CoefficientNames property

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Note:   The plot property name-value pairs apply to the first returned handle h(1).

'Color'

Color of the line or marker, a string or ColorSpec specification. For details, see linespec.

'LineStyle'

Type of line, a string or Chart Line Properties specification. For details, see linespec.

'LineWidth'

Width of the line or edges of filled area, in points, a positive scalar. One point is 1/72 inch.

Default: 0.5

'MarkerEdgeColor'

Color of the marker or edge color for filled markers, a string or ColorSpec specification. For details, see linespec.

'MarkerFaceColor'

Color of the marker face for filled markers, a string or ColorSpec specification. For details, see linespec.

'MarkerSize'

Size of the marker in points, a strictly positive scalar. One point is 1/72 inch.

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
ds = dataset(MPG,Weight);
ds.Year = ordinal(Model_Year);
mdl = fitlm(ds,'MPG ~ Year + Weight^2');

Create an added variable plot.

plotAdded(mdl)

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

Create an Added Variable Plot for Particular Variables

Create a model of car mileage as a function of weight and model year. Then create a plot to see the effect of the weight terms (Weight and Weight^2).

Create a linear model of mileage from the carsmall data.

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

Find the terms in the model corresponding to the Weight and Weight^2.

mdl.CoefficientNames
ans = 

    '(Intercept)' 'Weight' 'Year_76' 'Year_82' 'Weight^2'

The weight terms are 2 and 5.

Create an added variable plot with the weight terms.

coef = [2 5];
plotAdded(mdl,coef)

The plot illustrates that the weight terms are significant—a horizontal line does not fit between the confidence bounds.

Was this topic helpful?