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

    %% Fit Linear Model Using Default Confidence Intervals  
% Fit a linear regression model for auto mileage based on the |carbig| data. Then
% obtain the default 95% confidence intervals for the resulting model coefficients.   

%% 
% Load the data and create a table.
load carbig
Origin = nominal(Origin);
tbl = table(Horsepower,Weight,MPG,Origin);

%%
% Fit a linear regression model. Use horsepower, weight, and origin as
% predictor variables, and miles per gallon as the response variable.
modelspec = 'MPG ~ 1 + Horsepower + Weight + Origin';
mdl = fitlm(tbl,modelspec);  

%% 
% View the names of the coefficients. 
mdl.CoefficientNames  

%% 
% Find confidence intervals for the coefficients of the model. 
ci = coefCI(mdl)