Plot main effects of predictors in linear regression model
plotEffects( creates an effects plot
of the predictors in the linear regression model
effects plot shows the estimated main effect on the
response from changing each predictor value, averaging out the effects of the other
predictors. A horizontal line through an effect value indicates the 95% confidence
interval for the effect value.
Effects Plot for Linear Regression Model
carsmall data set and fit a linear regression model of the mileage as a function of model year, weight, and weight squared.
load carsmall tbl = table(MPG,Weight); tbl.Year = categorical(Model_Year); mdl = fitlm(tbl,'MPG ~ Year + Weight^2');
Create an effects plot.
The length of each horizontal line in the figure shows a 95% confidence interval for the effect on the response of the change shown for each predictor. For example, the estimated effect of changing
82 is an increase of about 8, and is between 6 and 10 with 95% confidence.
h — Line objects
Line objects, returned as a vector.
h(1) corresponds to
the circles that represent the effect estimates, and
h(j+1) corresponds to the 95% confidence interval for
the effect of predictor
j. Use dot notation to query and
set properties of line objects. For details, see Line Properties.
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,
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
plotEffects plots the effect value and the 95% confidence interval of the effect value for each predictor variable.
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. Use the x-axis values to view an estimated effect value and its confidence bounds.
LinearModelobject provides multiple plotting functions.
When creating a model, use
plotAddedto understand the effect of adding or removing a predictor variable.
After fitting a model, use
plotEffectsto understand the effect of a particular predictor. Use
plotInteractionto understand the interaction effect between two predictors. Also, use
plotSliceto plot slices through the prediction surface.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Introduced in R2012a