plotAdjustedResponse

Class: LinearModel

Adjusted response plot for linear regression model

Syntax

plotAdjustedResponse(mdl,var)
h = plotAdjustedResponse(mdl,var)
h = plotAdjustedResponse(mdl,var,Name,Value)

Description

plotAdjustedResponse(mdl,var) gives an adjusted response plot for the variable var in the mdl regression model.

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

h = plotAdjustedResponse(mdl,var,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.

var

Variable name, or scalar index of variable in mdl.CoefficientNames.

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

Adjusted Response Plot

The adjusted response plot shows the fitted response as a function of var, with the other predictors averaged out by averaging the fitted values over the data used in the fit. Adjusted data points are computed by adding the residual to the adjusted fitted value for each observation.

Examples

expand all

Plot Adjusted Responses

Plot the adjusted responses of a fitted linear model.

Load the carsmall data and fit a linear model of the mileage as a function of model year, weight, and weight squared.

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

Plot the effect of 'Weight' averaged over Year values.

plotAdjustedResponse(mdl,'Weight')

Plot the effect of Year averaged over 'Weight' values. Include the h output.

h = plotAdjustedResponse(mdl,'Year');

Change the adjusted data to black x instead of red o.

set(h(1),'Marker','x','Color','k')

Was this topic helpful?