coefCI

Class: LinearModel

Confidence intervals of coefficient estimates of linear model

Syntax

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

Description

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

ci = coefCI(mdl,alpha) returns confidence intervals with confidence level 1 - alpha.

Input Arguments

mdl

Linear model, as constructed by fitlm or stepwiselm.

alpha

Scalar from 0 to 1, the probability that the confidence interval does not contain the true value.

Default: 0.05

Output Arguments

ci

k-by-2 matrix of confidence intervals. The jth row of ci is the confidence interval of coefficient j of mdl. The name of coefficient j of mdl is in mdl.CoefficientNames.

Definitions

Confidence Interval

Assume that model assumptions hold (data comes from a generalized linear model represented by the formula mdl.Formula, and with observations that are independent conditional on the predictor values). Then row j of the confidence interval matrix ci gives a confidence interval [ci(j,1),ci(j,2)] computed such that, with repeated experimentation, a proportion 1 - alpha of the intervals will contain the true value of the coefficient.

Examples

expand all

Default Confidence Intervals

Create a linear model for auto mileage based on the carbig data. Then obtain confidence intervals for the resulting model coefficients.

Load the data and create a model.

load carbig
Origin = nominal(Origin);
ds = dataset(Horsepower,Weight,MPG,Origin);
modelspec = 'MPG ~ 1 + Horsepower + Weight + Origin';
mdl = fitlm(ds,modelspec);

View the names of the coefficients.

mdl.CoefNames
ans = 
  Columns 1 through 4
    '(Intercept)'    'Horsepower'    'Weight'    'Origin_France'

  Columns 5 through 8
    'Origin_Germany'    'Origin_Italy'    'Origin_Japan'    'Origin_Sweden'

  Column 9
    'Origin_USA'

Find confidence intervals for the coefficients of the model.

ci = coefCI(mdl)
ci =
       43.361       59.939
    -0.074778    -0.031499
   -0.0058669   -0.0037122
      -17.362     -0.34772
       -15.75      0.74338
      -17.209       0.0613
      -14.511       1.8738
      -18.582      -1.5036
      -17.311     -0.96419

Custom Confidence Intervals

Create a linear model for auto mileage based on the carbig data. Then obtain confidence intervals for the resulting model coefficients at the 99% level.

Load the data and create a model.

load carbig
Origin = nominal(Origin);
ds = dataset(Horsepower,Weight,MPG,Origin);
modelspec = 'MPG ~ 1 + Horsepower + Weight + Origin';
mdl fitlm(ds,modelspec);

Find 99% confidence intervals for the coefficients.

ci = coefCI(mdl,.01)
ci =
       40.737       62.564
    -0.081629    -0.024647
    -0.006208   -0.0033711
      -20.056       2.3459
      -18.361       3.3546
      -19.943       2.7955
      -17.104       4.4676
      -21.286       1.2002
      -19.899       1.6238

The confidence intervals are wider than the default 5% confidence intervals of Default Confidence Intervals.

Alternatives

You can create the intervals from the model coefficients in mdl.Coefficients.Estimate and an appropriate multiplier of the standard errors sqrt(diag(mdl.CoefficientCovariance)). The multiplier is tinv(1-alpha/2,dof), where level is the confidence level, and dof is the degrees of freedom (number of data points minus the number of coefficients).

Was this topic helpful?