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

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

%% 
% Find the terms in the model corresponding to the |Weight| and |Weight^2|. 
mdl.CoefficientNames 

%%
% 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 because a horizontal
% line does not fit between the confidence bounds.