# coefCI

Confidence intervals of coefficient estimates of generalized linear regression model

## Syntax

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

## Description

````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

Find the confidence intervals for the coefficients of a fitted generalized linear regression model.

Generate sample data using Poisson random numbers with two underlying predictors `X(:,1)` and `X(:,2)`.

```rng('default') % For reproducibility rndvars = randn(100,2); X = [2 + rndvars(:,1),rndvars(:,2)]; mu = exp(1 + X*[1;2]); y = poissrnd(mu);```

Create a generalized linear regression model of Poisson data.

`mdl = fitglm(X,y,'y ~ x1 + x2','Distribution','poisson')`
```mdl = Generalized linear regression model: log(y) ~ 1 + x1 + x2 Distribution = Poisson Estimated Coefficients: Estimate SE tStat pValue ________ _________ ______ ______ (Intercept) 1.0405 0.022122 47.034 0 x1 0.9968 0.003362 296.49 0 x2 1.987 0.0063433 313.24 0 100 observations, 97 error degrees of freedom Dispersion: 1 Chi^2-statistic vs. constant model: 2.95e+05, p-value = 0 ```

Find 95% (default) confidence intervals for the coefficients of the model.

`ci = coefCI(mdl)`
```ci = 3×2 0.9966 1.0844 0.9901 1.0035 1.9744 1.9996 ```

Find 99% confidence intervals for the coefficients.

```alpha = 0.01; ci = coefCI(mdl,alpha)```
```ci = 3×2 0.9824 1.0986 0.9880 1.0056 1.9703 2.0036 ```

## Input Arguments

collapse all

Generalized linear regression model, specified as a `GeneralizedLinearModel` object created using `fitglm` or `stepwiseglm`, or a `CompactGeneralizedLinearModel` object created 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.

## Version History

Introduced in R2012a