Main Content

coefCI

Confidence intervals of coefficient estimates of nonlinear regression model

Description

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

example

In R2025a: ci = coefCI(mdl,Name=Value) specifies options using one or more name-value arguments. For example, you can specify the significance level and the method for calculating the confidence intervals.

example

Examples

collapse all

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

Load the data and create a nonlinear model.

load carbig
tbl = table(Horsepower,Weight,MPG);
modelfun = @(b,x)b(1) + b(2)*x(:,1) + ...
    b(3)*x(:,2) + b(4)*x(:,1).*x(:,2);
beta0 = [1 1 1 1];
mdl = fitnlm(tbl,modelfun,beta0)
mdl = 
Nonlinear regression model:
    MPG ~ b1 + b2*Horsepower + b3*Weight + b4*Horsepower*Weight

Estimated Coefficients:
           Estimate         SE         tStat       pValue  
          __________    __________    _______    __________

    b1        63.558        2.3429     27.127    1.2343e-91
    b2      -0.25084      0.027279    -9.1952    2.3226e-18
    b3     -0.010772    0.00077381    -13.921    5.1372e-36
    b4    5.3554e-05    6.6491e-06     8.0542    9.9336e-15


Number of observations: 392, Error degrees of freedom: 388
Root Mean Squared Error: 3.93
R-Squared: 0.748,  Adjusted R-Squared 0.746
F-statistic vs. constant model: 385, p-value = 7.26e-116

All the coefficients have extremely small p-values. This means a confidence interval around the coefficients will not contain the point 0, unless the confidence level is very high.

Find 95% confidence intervals for the coefficients of the model.

ci = coefCI(mdl)
ci = 4×2

   58.9515   68.1644
   -0.3045   -0.1972
   -0.0123   -0.0093
    0.0000    0.0001

The confidence interval for b4 seems to contain 0. Examine it in more detail.

ci(4,:)
ans = 1×2
10-4 ×

    0.4048    0.6663

As expected, the confidence interval does not contain the point 0.

Load the carbig data set.

load carbig

The vectors Horsepower and Weight contain data for car horsepower and weight, respectively. The vector MPG contains data for car mileage.

Use the table function to create a table from the data in Horsepower, Weight, and MPG.

tbl = table(Horsepower,Weight,MPG,VariableNames=["HP","Weight","MPG"]);

Fit a nonlinear model to the data in tbl. Use the car horsepower and weight data as predictor variables, and the mileage data as the response.

modelfun = @(b,x)b(1) + b(2)*x(:,1) + ...
    b(3)*x(:,2) + b(4)*x(:,1).*x(:,2);
beta0 = [1 1 1 1];
mdl = fitnlm(tbl,modelfun,beta0)
mdl = 
Nonlinear regression model:
    MPG ~ b1 + b2*HP + b3*Weight + b4*HP*Weight

Estimated Coefficients:
           Estimate         SE         tStat       pValue  
          __________    __________    _______    __________

    b1        63.558        2.3429     27.127    1.2343e-91
    b2      -0.25084      0.027279    -9.1952    2.3226e-18
    b3     -0.010772    0.00077381    -13.921    5.1372e-36
    b4    5.3554e-05    6.6491e-06     8.0542    9.9336e-15


Number of observations: 392, Error degrees of freedom: 388
Root Mean Squared Error: 3.93
R-Squared: 0.748,  Adjusted R-Squared 0.746
F-statistic vs. constant model: 385, p-value = 7.26e-116

mdl is a NonLinearModel object that contains the results of fitting the model specified by model to the data in tbl.

Calculate 99% Wald confidence intervals for the coefficients b1 and b3.

coefCI(mdl,Alpha=0.01,Coefficient=["b1" "b3"])
ans = 2×2

   57.4931   69.6228
   -0.0128   -0.0088

Calculate 99% likelihood-ratio confidence intervals for the same coefficients.

coefCI(mdl,Alpha=0.01,Coefficient=["b1" "b3"],Method="likelihood-ratio")
ans = 2×2

   57.5538   69.5621
   -0.0128   -0.0088

The output shows that both methods of calculating the confidence intervals for b1 and b3 yield similar results.

Input Arguments

collapse all

Nonlinear regression model, specified as a NonLinearModel object created using fitnlm.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: coefCI(mdl,Alpha=0.01,Coefficient=[1,2],Method="likelihood-ratio") calculates 99% likelihood-ratio confidence intervals for the first and second coefficients in the model mdl.

Since R2025a

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: Alpha=0.01

Data Types: single | double

Since R2025a

Coefficients, specified as a string scalar or vector, or a numeric scalar vector. coefCI calculates confidence intervals for the coefficients you specify in CoefficientNames.

When CoefficientNames is a string scalar or vector, it contains the name of the coefficient or names of the coefficients. When CoefficientNames is a numeric scalar or vector, it contains the index of the coefficient or indices of the coefficients.

The default value for CoefficientNames is 1:m where m is the number of coefficients in mdl.

Example: CoefficientNames=["b1" "b2"]

Data Types: double | single | string | char

Since R2025a

Confidence interval type, specified as one of the following:

  • "wald" — Calculate Wald confidence intervals. coefCI calculates the upper and lower bounds of a Wald interval by adding and subtracting (respectively) a multiple of the standard error from the coefficient estimate.

  • "likelihood-ratio" — Calculate likelihood-ratio confidence intervals. coefCI calculates likelihood-ratio intervals by determining the coefficient values for which the profile likelihood drops below a threshold.

Example: Method="likelihood-ratio"

Data Types: string | char

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

More About

collapse all

Alternative Functionality

You can calculate the likelihood-ratio confidence intervals, profile loglikelihood, and corresponding coefficient values for a single coefficient using the profileLikelihood function. profileLikelihood does not have an option to calculate Wald intervals.

Version History

Introduced in R2012a

expand all