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

    %% Assess Significance of Regression Coefficients Using t-statistic  
% This example shows how to test for the significance of the regression
% coefficients using t-statistic.   

% Copyright 2015 The MathWorks, Inc.


%% 
% Load the sample data and fit the linear regression model. 
load hald
mdl = fitlm(ingredients,heat) 

%%
% You can see that for each coefficient, |tStat = Estimate/SE|. The $p$-values
% for the hypotheses tests are in the |pValue| column. Each $t$-statistic
% tests for the significance of each term given other terms in the model.
% According to these results, none of the coefficients seem significant
% at the 5% significance level, although the R-squared value for the model
% is really high at 0.97. This often indicates possible multicollinearity
% among the predictor variables.  

%% 
% Use stepwise regression to decide which variables to include in the model. 
load hald
mdl = stepwiselm(ingredients,heat) 

%%
% In this example, |stepwiselm| starts with the constant model (default)
% and uses forward selection to incrementally add |x4| and |x1|. Each predictor
% variable in the final model is significant given the other one is in the
% model. The algorithm stops when adding none of the other predictor variables
% significantly improves in the model. For details on stepwise regression,
% see |stepwiselm|.