coefCI
Confidence intervals of coefficient estimates of linear regression model
Description
Examples
Find Confidence Intervals for Model Coefficients
Fit a linear regression model and obtain the default 95% confidence intervals for the resulting model coefficients.
Load the carbig
data set and create a table in which the Origin
predictor is categorical.
load carbig
Origin = categorical(cellstr(Origin));
tbl = table(Horsepower,Weight,MPG,Origin);
Fit a linear regression model. Specify Horsepower
, Weight
, and Origin
as predictor variables, and specify MPG
as the response variable.
modelspec = 'MPG ~ 1 + Horsepower + Weight + Origin';
mdl = fitlm(tbl,modelspec);
View the names of the coefficients.
mdl.CoefficientNames
ans = 1x9 cell
{'(Intercept)'} {'Horsepower'} {'Weight'} {'Origin_France'} {'Origin_Germany'} {'Origin_Italy'} {'Origin_Japan'} {'Origin_Sweden'} {'Origin_USA'}
Find confidence intervals for the coefficients of the model.
ci = coefCI(mdl)
ci = 9×2
43.3611 59.9390
-0.0748 -0.0315
-0.0059 -0.0037
-17.3623 -0.3477
-15.7503 0.7434
-17.2091 0.0613
-14.5106 1.8738
-18.5820 -1.5036
-17.3114 -0.9642
Specify Confidence Level
Fit a linear regression model and obtain the confidence intervals for the resulting model coefficients using a specified confidence level.
Load the carbig
data set and create a table in which the Origin
predictor is categorical.
load carbig
Origin = categorical(cellstr(Origin));
tbl = table(Horsepower,Weight,MPG,Origin);
Fit a linear regression model. Specify Horsepower
, Weight
, and Origin
as predictor variables, and specify MPG
as the response variable.
modelspec = 'MPG ~ 1 + Horsepower + Weight + Origin';
mdl = fitlm(tbl,modelspec);
Find 99% confidence intervals for the coefficients.
ci = coefCI(mdl,.01)
ci = 9×2
40.7365 62.5635
-0.0816 -0.0246
-0.0062 -0.0034
-20.0560 2.3459
-18.3615 3.3546
-19.9433 2.7955
-17.1045 4.4676
-21.2858 1.2002
-19.8995 1.6238
The confidence intervals are wider than the default 95% confidence intervals in Find Confidence Intervals for Model Coefficients.
Input Arguments
mdl
— Linear regression model object
LinearModel
object | CompactLinearModel
object
Linear regression model object, specified as a LinearModel
object created by using fitlm
or stepwiselm
, or a CompactLinearModel
object created by using compact
.
alpha
— Significance level
0.05 (default) | numeric value in the range [0,1]
Significance level for the confidence interval, specified as a numeric value in the
range [0,1]. The confidence level of ci
is equal to 100(1 – alpha
)%. alpha
is the probability that the confidence
interval does not contain the true value.
Example: 0.01
Data Types: single
| double
Output Arguments
ci
— Confidence intervals
numeric matrix
Confidence intervals, returned as a k-by-2 numeric matrix, where
k is the number of coefficients. The jth row
of ci
is the confidence interval of the jth
coefficient of mdl
. The name of coefficient j is
stored in the CoefficientNames
property of
mdl
.
Data Types: single
| double
More About
Confidence Interval
The coefficient confidence intervals provide a measure of precision for regression coefficient estimates.
A 100(1 – α)% confidence interval gives the range for the corresponding regression coefficient with 100(1 – α)% confidence, meaning that 100(1 – α)% of the intervals resulting from repeated experimentation will contain the true value of the coefficient.
The software finds confidence intervals using the Wald method. The 100(1 – α)% confidence intervals for regression coefficients are
where bi is the coefficient estimate, SE(bi) is the standard error of the coefficient estimate, and t(1–α/2,n–p) is the 100(1 – α/2) percentile of the t-distribution with n – p degrees of freedom. n is the number of observations and p is the number of regression coefficients.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2012a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)