www.gusucode.com > stats 源码程序 matlab案例代码 > stats/PlotsToUnderstandTermsEffectsExample.m

    %% Plots to Understand Terms Effects
% This example shows how to understand the effect of each term in a
% regression model using a variety of available plots.
%%
% Load the sample data.

% Copyright 2015 The MathWorks, Inc.

load carsmall
%%
% Create a model of mileage from some predictors in the |carsmall| data.
ds = dataset(Weight,MPG,Cylinders);
ds.Cylinders = ordinal(ds.Cylinders);
mdl = fitlm(ds,'MPG ~ Cylinders*Weight + Weight^2');
%%
% Create an added variable plot with |Weight^2| as the added variable.
plotAdded(mdl,'Weight^2')
%%
% This plot shows the results of fitting both |Weight^2| and |MPG| to the terms
% other than |Weight^2| . The reason to use |plotAdded| is to understand what
% additional improvement in the model you get by adding |Weight^2| . The
% coefficient of a line fit to these points is the coefficient of |Weight^2|
% in the full model. The |Weight^2| predictor is just over the edge of
% significance ( |pValue| < 0.05) as you can see in the coefficients table
% display. You can see that in the plot as well. The confidence bounds look
% like they could not contain a horizontal line (constant y), so a
% zero-slope model is not consistent with the data.
%%
% Create an added variable plot for the model as a whole.
plotAdded(mdl)
%%
% The model as a whole is very significant, so the bounds don't come close
% to containing a horizontal line. The slope of the line is the slope of a
% fit to the predictors projected onto their best-fitting direction, or in
% other words, the norm of the coefficient vector.