Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

coefCI

Class: CompactLinearModel

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 using the confidence level 1 – alpha.

Input Arguments

expand all

Linear model object, specified as a full LinearModel object constructed using fitlm or stepwiselm, or a compacted CompactLinearModel object constructed using compact.

Confidence interval, specified as a numeric value in the range [0,1]. alpha is the probability that the confidence interval does not contain the true value.

Output Arguments

expand all

Confidence intervals, returned as a k-by-2 numeric matrix. The jth row of ci is the confidence interval of coefficient j of mdl. The name of coefficient j is stored in the mdl property 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

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
ans =

  1×9 cell array

  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.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 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 table.

load carbig
Origin = nominal(Origin);
tbl = table(Horsepower,Weight,MPG,Origin);

Fit a linear regression model using horsepower, weight, and origin as the predictor variables, and miles per gallon 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 =

   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 5% 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?