Syntax

Description

plotInteraction(mdl,var1,var2)
creates a plot of the main effects of the
two selected predictors var1 and var2 and
their conditional effects
in the linear regression model mdl. Horizontal lines through
the effect values indicate their 95% confidence intervals.

plotInteraction(mdl,var1,var2,ptype)
specifies the plot type ptype. For example, if
ptype is 'predictions', then
plotInteraction plots the adjusted response function as a
function of the second predictor, with the first predictor fixed at specific values.
For details, see Conditional Effect.

h = plotInteraction(___)
returns line objects using any of the input argument combinations in the previous
syntaxes. Use h to modify the properties of a specific line
after you create the plot. For a list of properties, see Line Properties.

pValue of the interaction term Acceleration*Horsepower is very small, meaning that the interaction term is statistically significant.

Create an interaction plot that shows the main effects and conditional effects of Horsepower and Acceleration.

plotInteraction(mdl,'Horsepower','Acceleration')

For each predictor, the main effect point and its conditional effect points are not vertically aligned. Therefore, you cannot find any vertical lines that pass through the confidence intervals of the main and conditional effect points for each predictor. This plot indicates the existence of interaction effects on the response variable.

For comparison, create an interaction plot for Displacement and Horsepower. This p-value of this interaction term (Displacement*Horsepower) is large, meaning that the interaction term is not statistically significant.

plotInteraction(mdl,'Displacement','Horsepower')

For each predictor, the main effect point and its conditional effect points are aligned vertically. This plot indicates no interaction.

pValue of the interaction term Acceleration*Horsepower is very small, meaning that the interaction term is statistically significant.

Create an interaction plot that shows the adjusted response function as a function of Acceleration, with Horsepower fixed at specific values.

plotInteraction(mdl,'Horsepower','Acceleration','predictions')

The curves are not parallel. This plot indicates interactions between the predictors.

For comparison, create an interaction plot for the Displacement and Horsepower. The p-value of this interaction term (Displacement*Horsepower) is large, meaning that the interaction term is not statistically significant.

First variable for the plot, specified as a character vector or string
array of the variable name in mdl.VariableNames
(VariableNames property of mdl),
or a positive integer representing the index of a variable in
mdl.VariableNames.

Second variable for the plot, specified as a character vector or string
array of the variable name in mdl.VariableNames
(VariableNames property of mdl),
or a positive integer representing the index of a variable in
mdl.VariableNames.

Data Types: char | string | single | double

ptype — Plot type'effects' (default) | 'predictions'

Plot type, specified as one of these values:

'effects' —
plotInteraction creates a plot of the main
effects of the two selected predictors var1 and
var2 and their conditional effects.
Horizontal lines through the effect values indicate their 95%
confidence intervals.

'predictions' —
plotInteraction plots the adjusted response
function as a function of var2, with
var1 fixed at specific values.

Output Arguments

h — Line objectsvector

Line objects, returned as a vector. Use dot notation to query and set
properties of the line objects. For details, see Line Properties.

If the plot type is 'effects' (default),
h(1) corresponds to the circles that represent the
main effect estimates, and h(2) and
h(3) correspond to the 95% confidence intervals for
the two main effects. The remaining entries in h
correspond to the conditional effects and their confidence intervals. The
line objects associated with the main effects have the tag
'main'. The line objects associated with the
conditional effects of var1 and
var2 have the tags
'conditional1' and 'conditional2',
respectively.

If the plot type is 'predictions', each entry in
h corresponds to each curve on the plot.

More About

Main Effect

An effect, or main effect, of a predictor represents an effect of one
predictor on the response from changing the predictor value while averaging out the
effects of the other predictors.

For a predictor variable xs, the effect is defined by

g(xsi)
–
g(xsj)
,

where g is an Adjusted Response function. The
plotEffects function chooses the observations
i and j as follows. For a categorical
variable that is not ordinal,
xsi
and
xsj
are the predictor values that produce the maximum and minimum adjusted responses,
respectively, so that the effect value is always positive. For a numeric variable or
an ordinal categorical variable, the function chooses two predictor values that
produce the minimum and maximum adjusted responses where xsi
<
xsj.

plotEffects plots the effect value and the 95% confidence interval of the effect value for each predictor variable.

Adjusted Response

An adjusted response function describes the relationship between the fitted response and a single predictor, with the other predictors averaged out by averaging the fitted values over the data used in the fit.

A regression model for the predictor variables (x1,
x2, …,
xp) and the response variable y has the form

yi =
f(x1i,
x2i, …,
xpi) +
ri,

where f is a fitted regression function and
r is a residual. The subscript i represents the
observation number.

The adjusted response function for the first predictor variable
x1, for example, is defined as

g(x1)=1n∑i=1nf(x1,x2i,x3i,...,xpi),

where n is the number of observations. The adjusted
response data value is the sum of the adjusted fitted value and the residual for each observation.

Conditional Effect

When a model contains an interaction term, the main effect of one
predictor depends on the value of another predictor that interacts with it. In this
case, a conditional effect of one predictor given a specific value of another is
helpful in understanding the actual effect of both predictors. You can examine
whether the effect of one predictor depends on the value of another by using
conditional effect values.

To define a conditional effect, define the adjusted response function as a
function of two predictor variables. For example, the adjusted response function of
x1 and
x2 is

h(x1,x2)=1n∑i=1nf(x1,x2,x3i,...,xpi),

where f is a fitted regression function, and
n is the number of observations.

The conditional effect of one predictor
(x2) given a specific value of another
predictor (x1k) is
defined by

h(x1k,x2i)
-
h(x1k,x2j).

To compute conditional effect values,
plotInteraction chooses the observations
i and j of
x2 in the same way as when the
function computes the Main Effect and chooses the
x1k values. If
x1 is a categorical variable, then
plotInteraction computes the conditional effect for all
levels of x1. If
x1 is a numeric variable, then
plotInteraction computes the conditional effect for three
values of x1: the minimum value of
x1, the maximum value of
x1, and the average value of the
minimum and maximum.

If the plot type is 'effects' (default),
plotInteraction plots the main effects of the two selected
predictors, their conditional effects, and the 95% confidence bounds for the effect
values.

If the plot type is 'predictions',
plotInteraction plots the adjusted response function as a
function of the second predictor, with the first predictor fixed at specific values.
For example, plotInteraction(mdl,'x1','x2','predictions') plots
the curve of h(x1k,
x2) for each
x1k value.

Tips

The data cursor displays the values of the selected plot point in a data tip (small text
box located next to the data point). The data tip includes the x-axis and
y-axis values for the selected point, along with the observation name
or number.

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.