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

    %% Test Significance of Linear Model Coefficient  
% Test the |Weight^2| coefficient in a linear model of mileage as a function
% of the weight, weight squared, and model year.   

%% 
% Load the data and make a table, where the model year is an ordinal variable. 
load carsmall
tbl = table(MPG,Weight);
tbl.Year = ordinal(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight + Weight^2');  

%% 
% Test the significance of the |Weight^2| coefficient. To do so, find the
% coefficient corresponding to |Weight^2|. 
mdl.CoefficientNames 

%%
% |Weight^2| is the fifth (final) coefficient.  

%% 
% Test the significance of the |Weight^2| coefficient. 
p = coefTest(mdl,[0 0 0 0 1])