# coefCI

Confidence intervals of coefficient estimates of linear regression model

## Syntax

``ci = coefCI(mdl)``
``ci = coefCI(mdl,alpha)``

## Description

example

````ci = coefCI(mdl)` returns 95% confidence intervals for the coefficients in `mdl`.```

example

````ci = coefCI(mdl,alpha)` returns confidence intervals using the confidence level ```1 – alpha```.```

## Examples

collapse all

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 Columns 1 through 4 {'(Intercept)'} {'Horsepower'} {'Weight'} {'Origin_France'} Columns 5 through 7 {'Origin_Germany'} {'Origin_Italy'} {'Origin_Japan'} Columns 8 through 9 {'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 ```

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

collapse all

Linear regression model object, specified as a `LinearModel` object created by using `fitlm` or `stepwiselm`, or a `CompactLinearModel` object created by using `compact`.

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

collapse all

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`

collapse all

### Confidence Interval

The coefficient confidence intervals provide a measure of precision for regression coefficient estimates.

A 100(1 – α)% confidence interval gives the range that the corresponding regression coefficient will be in 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

`${b}_{i}±{t}_{\left(1-\alpha /2,n-p\right)}SE\left({b}_{i}\right),$`

where bi is the coefficient estimate, SE(bi) is the standard error of the coefficient estimate, and t(1–α/2,np) is the 100(1 – α/2) percentile of t-distribution with n – p degrees of freedom. n is the number of observations and p is the number of regression coefficients.