www.gusucode.com > stats 源码程序 matlab案例代码 > stats/LinearModelUsingStepwiseRegressionExample.m
%% Fit a Linear Model Using Stepwise Regression %% % Load the sample data. load hald %% % |hald| contains hardening data for 13 different concrete compositions. % |heat| is the heat of hardening after 180 days. |ingredients| is the percentage % of each different ingredient in the cement sample. %% % Fit a linear model to the data. Set the criterion value to enter the model % as 0.06. mdl = stepwiselm(ingredients,heat,'PEnter',0.06) %% % By default, the starting model is the constant model. |stepwiselm| performs % forward selection and |x4|, |x1|, and |x2|, respectively, as the corresponding % $p$-values are less than the |PEnter| value of 0.06. |stepwiselm| later % uses backward elimination and eliminates |x4| from the model because, % once |x2| is in the model, the $p$-value of |x4| is higher than % the default value of |PRemove|, 0.1.