Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

coefCI

Clase: CompactLinearModel

Confidence intervals of coefficient estimates of linear model

Sintaxis

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.

Argumentos de entrada

expandir todo

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

expandir todo

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.

Ejemplos

expandir todo

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 = 1x9 cell array
  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 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 = 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 5% confidence intervals.

Más acerca de

expandir todo

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